Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 我的数组是多维的吗?_Php_Arrays - Fatal编程技术网

Php 我的数组是多维的吗?

Php 我的数组是多维的吗?,php,arrays,Php,Arrays,我有以下代码: <?php $res = array ( array ('vendor_id' => '21', 'box_1' => array ([0]=>array('product_id' => '80', 'pcs' => '1'), [1]=>array('product_id' => '85', 'pcs' =

我有以下代码:

<?php

$res = array ( array ('vendor_id' => '21',
                      'box_1' => array ([0]=>array('product_id' => '80', 'pcs' => '1'),
                                        [1]=>array('product_id' => '85', 'pcs' => '5')),
                      'box_2' => array ([0]=>array('product_id' => '80', 'pcs' => '3'),
                                        [1]=>array('product_id' => '92', 'pcs' => '9'))
             ));

echo '<pre>';
print_r($res);

?>

我的阵列怎么了?为什么我会收到那个错误信息。谢谢…

您不需要指定索引的
[0]
[1]
。试试这个

$res = array ( array ('vendor_id' => '21',
                    'box_1' => array (
                                        0 => array('product_id' => '80', 'pcs' => '1'),
                                        1 => array('product_id' => '85', 'pcs' => '5')
                    ),
                    'box_2' => array (
                                        0 => array('product_id' => '80', 'pcs' => '3'),
                                        1 => array('product_id' => '92', 'pcs' => '9')
                    )
        ));
echo '<pre>';print_r($res); echo '</pre>';
';
您不需要指定索引的
[0]
[1]
。试试这个

$res = array ( array ('vendor_id' => '21',
                    'box_1' => array (
                                        0 => array('product_id' => '80', 'pcs' => '1'),
                                        1 => array('product_id' => '85', 'pcs' => '5')
                    ),
                    'box_2' => array (
                                        0 => array('product_id' => '80', 'pcs' => '3'),
                                        1 => array('product_id' => '92', 'pcs' => '9')
                    )
        ));
echo '<pre>';print_r($res); echo '</pre>';
'; 而不是

只能将数字部分用作键:

当然,数字键不是必需的。您可以不使用任何键添加这些数组。

而不是

只能将数字部分用作键:

当然,数字键不是必需的。您可以不使用任何键添加这些数组

这是你的错误:

[0]
是一个包含数字0的数组。 不能将一个数组作为另一个数组中的键。只使用数字
0
或字符串
“0”

这是你的错误:

[0]
是一个包含数字0的数组。 不能将一个数组作为另一个数组中的键。只使用数字
0
或字符串
“0”

$res = array ( array ('vendor_id' => '21',
                    'box_1' => array (
                                        0 => array('product_id' => '80', 'pcs' => '1'),
                                        1 => array('product_id' => '85', 'pcs' => '5')
                    ),
                    'box_2' => array (
                                        0 => array('product_id' => '80', 'pcs' => '3'),
                                        1 => array('product_id' => '92', 'pcs' => '9')
                    )
        ));
echo '<pre>';print_r($res); echo '</pre>';
[0] => array('product_id' => '80', 'pcs' => '1')
0 => array('product_id' => '80', 'pcs' => '1')
'box_1' => array ([0]=>array('product_id' => '80', 'pcs' => '1'),