简体   繁体   中英

how to get post value from multiple array in yii2

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM