我想在 yii2 中获取 post 数组的值, 我有这样的数组
[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] =>
)
)
我试图用下面的函数获取值,但我无法获取它。
$request = Yii::$app->request;
$request->post('Brand[name][0]');
如何获取名称数组的值? 我不想像 $_POST['Brand']['name'][0] 那样使用它,我只需要使用 yii2 函数
最佳答案
$var = ArrayHelper::getValue($request->post(), 'Brand.name.0');
$request->post()
方法的工作方式,它只是从 $_POST
返回给你一个值,所以用法是:
$brand = $request->post('Brand'); // now $brand variable contains $_POST['Brand']
$var = $brand['name'][0]
关于yii2 - yii2如何从多个数组中获取post值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34717266/