If I have:
$_POST['test']
then can I use:
$request->getParameter('test');
But how can I use this if I have $_POST['test']['two']
?
Now only one way do to it:
$arr = $request->getParameter('test');
$two = $arr['two'];
Edited:
In PHP 5.4 you can do it $request->getParameter('test')['two'];
$request->getParameter('test')['two'];
As of Symfony 2, there's even a prettier solution to get array values with the Symfony Request:
$request->get("test[two]", null, true)
The third parameter of get()
, $deep
, is false by default and decides whether you can access array keys.
See the documentation of the ParameterBag:
boolean $deep: If true, a path like foo[bar] will find deeper items
http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/ParameterBag.html#method_get
As antongorodezkiz pointed out in his comment to this answer, please note that this "is deprecated since version 2.8 and will be removed in 3.0."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With