Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 505
Nikul Avatar asked Dec 14 '25 06:12

Nikul


1 Answers

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]
like image 56
Tony Avatar answered Dec 16 '25 21:12

Tony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!