how to get post value from multiple array in yii2

本小妞迷上赌 提交于 2019-12-23 16:33:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!