Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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_Multidimensional Array_Associative Array - Fatal编程技术网

Php 将一维数组转换为多维数组

Php 将一维数组转换为多维数组,php,arrays,multidimensional-array,associative-array,Php,Arrays,Multidimensional Array,Associative Array,我需要在php中将一维数组转换为多维数组 还需要将此索引数组转换为关联数组 [0] => 9 [1] => Bang Bhasm [2] => 123 [3] => 161 [4] => 6 [5] => Sales [6] => Cash [7] => Sales-GST @12% [8] => Output CGST @6% [9] => 10 [10] => Be Fresh Churan [11] => 123 [1

我需要在php中将一维数组转换为多维数组 还需要将此索引数组转换为关联数组

[0] => 9
[1] => Bang Bhasm
[2] => 123
[3] => 161
[4] => 6
[5] => Sales
[6] => Cash
[7] => Sales-GST @12%
[8] => Output CGST @6%
[9] => 10
[10] => Be Fresh Churan
[11] => 123
[12] => 154
[13] => 6
[14] => Sales
[15] => Cash
[16] => Sales-GST @12%
[17] => Output CGST @6%
我想要这个预期输出:-

 [0] Array (
        [0] => 9 
        [1] => Bang Bhasm 
        [2] => 123 
        [3] => 161 
        [4] => 6 
        [5] => Sales 
        [6] => Cash 
        [7] => Sales-GST @12% 
        [8] => Output CGST @6% 
        [9] => 10 
        )
[1] Array( 
        [10] => Be Fresh Churan
        [11] => 123 
        [12] => 154
        [13] => 6 
        [14] => Sales 
        [15] => Cash 
        [16] => Sales-GST @12% 
        [17] => Output CGST @6%
        ) I

php中的每个数组都是关联数组。如果未定义键,则php会自动将数组转换为索引数组

您可能需要:

$single_dimension_array=array(9,'Bang Bhasm',123,161,6,'Sales','Cash','Sales GST@12%,'Output CGST@6%,'10,'Be Fresh Churan',123,154,6,'Sales','Cash','Sales GST@12%,'Output CGST@6%);
还是这个

$multi\u dimension\u array=array(
数组(9,'Bang Bhasm',123,161,6,'Sales','Cash','Sales GST@12%','Output CGST@6%'),
数组(10,'Be Fresh Churan',123,154,6,'Sales','Cash','Sales GST@12%','Output CGST@6%');

这会很有帮助:

您尝试过什么?您的预期输出是什么?我希望此数组采用这种格式[0]数组([0]=>9[1]=>Bang Bhasm[2]=>123[3]=>161[4]=>6[5]=>Sales[6]=>Cash[7]=>Sales GST@12%[8]=>output CGST@6%[9]=>10)[1]数组([10]=>Be Fresh Churan[11]=>123[12]=>154[13]=>6[14]=>Sales[15]=>Cash[16]=>Sales GST@12%[17]=>Output CGST@6%)我想要这种格式的数组。你可以在你的问题中添加你想要的数组格式,以便大家都能更好地理解吗