Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP数组的循环throuh数组_Php_Arrays_Codeigniter 3 - Fatal编程技术网

PHP数组的循环throuh数组

PHP数组的循环throuh数组,php,arrays,codeigniter-3,Php,Arrays,Codeigniter 3,我有一个数组,它是从我的$\u POST数据中获得的,带有这个值 Array ( [unit] => [items] => Array ( [1] => Array ( [category] => 1 [items] => 5 [qty] => 1 [jan] => 1 [feb] =&g

我有一个数组,它是从我的
$\u POST
数据中获得的,带有这个值

Array ( 
    [unit] => 
    [items] => Array ( 
        [1] => Array ( 
            [category] => 1 
            [items] => 5 
            [qty] => 1 
            [jan] => 1 
            [feb] => 
            [mar] => 
            [apr] => 
            [may] =>
            [jun] => 
            [jul] => 
            [aug] => 
            [sep] => 
            [oct] => 
            [nov] => 
            [dec] => 
        ) 
        [2] => Array ( 
            [category] => 1 
            [items] => 20 
            [qty] => 1 
            [jan] => 1 
            [feb] => 
            [mar] => 
            [apr] => 
            [may] => 
            [jun] => 
            [jul] => 
            [aug] => 
            [sep] => 
            [oct] => 
            [nov] => 
            [dec] => 
        ) 
        [3] => Array ( 
            [category] => 1 
            [items] => 27 
            [qty] => 1 
            [jan] => 1 
            [feb] => 
            [mar] => 
            [apr] => 
            [may] => 
            [jun] => 
            [jul] => 
            [aug] => 
            [sep] => 
            [oct] => 
            [nov] => 
            [dec] => 
        ) 
    ) 
    [action] => 
)
我试图获取每个数组,并将其传递给我的模型以插入数据库。例如,获取
[items]
的数组,其中
[1]

我试过使用

$array_col = array_column($_POST, 'items');
print_r($array_col);
但它返回的
Array()
为空


谢谢您的回答。

我怀疑您的数据在
$\u POST['items']
中。 因此:

然后,要遍历它们,需要一个
循环

foreach($array_col as $col){
  // Do your stuff here
  print_r($col);
}

我怀疑您的数据在
$\u POST['items']
中。 因此:

然后,要遍历它们,需要一个
循环

foreach($array_col as $col){
  // Do your stuff here
  print_r($col);
}

来自PHP文档…

array_column()返回由column_键标识的单个输入列的值。可选地,可以提供索引键,以通过输入数组的索引键列中的值对返回数组中的值进行索引


检查是否有数组键索引-“
项”处于不同的级别(级别0和级别2)

来自PHP文档…

array_column()返回由column_键标识的单个输入列的值。可选地,可以提供索引键,以通过输入数组的索引键列中的值对返回数组中的值进行索引

检查是否有数组键索引-“
项”处于不同级别(级别0和级别2)

您可以使用此代码

foreach($_POST['items'] as $a){
    // Code will go here. Whatever.
    print_r($a);
}
您可以使用此代码

foreach($_POST['items'] as $a){
    // Code will go here. Whatever.
    print_r($a);
}

谢谢你,但我想单独获得每个
$\u帖子['items']
。像先是
[1]
然后是
[2]
等等……谢谢你,但我想分别获得每个
$\u帖子['items']
。比如先是
[1]
,然后是
[2]
等等。。。