如何从yii2中的多个数组中获取post值 [英] how to get post value from multiple array in yii2

查看:35
本文介绍了如何从yii2中的多个数组中获取post值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 yii2 中获取 post 数组的值,我有这样的数组

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]');

如何获取名称数组的值?我不想像 $_POST['Brand']['name'][0] 那样使用它,我只需要使用 yii2 函数

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

推荐答案

尝试使用 ArrayHelper 类

$var = ArrayHelper::getValue($request->post(), 'Brand.name.0');

$request->post() 方法的工作方式,它只是从 $_POST 返回一个值,所以用法是:

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]

这篇关于如何从yii2中的多个数组中获取post值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆