问题
I want to get value of post array in yii2, I have array like this
[Brand] => Array
(
[name] => Array
(
[0] => testing
[1] => jkhkjhjkhjk
)
[tagline] => Array
(
[0] => kjhjkh
[1] =>
)
[meta_keyword] => Array
(
[0] =>
[1] =>
)
[sort_order] =>
[image] => brand/1452498338552.jpg
[status] =>
)
)
I tried to get value with below function, but i am unable to get it.
$request = Yii::$app->request;
$request->post('Brand[name][0]');
How can i get value of name array ? I don't want to use it like $_POST['Brand']['name'][0], I need to use only yii2 function
回答1:
Try to use ArrayHelper class
$var = ArrayHelper::getValue($request->post(), 'Brand.name.0');
The way $request->post()
method works, it just returns to you a value from $_POST
, so usage is:
$brand = $request->post('Brand'); // now $brand variable contains $_POST['Brand']
$var = $brand['name'][0]
来源:https://stackoverflow.com/questions/34717266/how-to-get-post-value-from-multiple-array-in-yii2