Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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/9/blackberry/2.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_Array Column - Fatal编程技术网

如何使用php将多维数组的数组替换为该数组的项?

如何使用php将多维数组的数组替换为该数组的项?,php,arrays,multidimensional-array,array-column,Php,Arrays,Multidimensional Array,Array Column,在下面的多维数组中,我将如何用[SUB1] Array ( [0] => Array ( [SUB1] => AAA111 [SUB2] => Description 1 [SUB3] => 10 ) [1] => Array ( [SUB1] => BBB222 [SUB2]

在下面的多维数组中,我将如何用
[SUB1]

Array
(
    [0] => Array
        (
            [SUB1] => AAA111
            [SUB2] => Description 1
            [SUB3] => 10
        )

    [1] => Array
        (
            [SUB1] => BBB222
            [SUB2] => Description 2
            [SUB3] => 20
        )

    [2] => Array
        (
            [SUB1] => CCC333
            [SUB2] => Description 3
            [SUB3] => 30
        )

)
我已经设法使用了
$sub1=array\u column($array,'sub1')
获取下面的数组,但我不确定是否存在一个简单的函数来使用它用值替换原始数组中的索引

Array
(
    [0] => AAA111
    [1] => BBB222
    [2] => CCC333
)
编辑:

期望输出:

Array
(
    [AAA111] => Array
        (
            [SUB2] => Description 1
            [SUB3] => 10
        )

    [BBB222] => Array
        (
            [SUB2] => Description 2
            [SUB3] => 20
        )

    [CCC333] => Array
        (
            [SUB2] => Description 3
            [SUB3] => 30
        )

)

请检查下面的示例,其中$test等于您的主数组

$output = [];
foreach ($test as $t) {
    $first = reset($t);
    $remaining = array_shift($t);
    $output[$first] = $t;
}

echo '<pre>';
print_r($output);
$output=[];
foreach($t作为测试){
$first=重置($t);
$剩余=阵列移位($t);
$output[$first]=$t;
}
回声';
打印(输出);

请检查下面的示例,其中$test等于您的主数组

$output = [];
foreach ($test as $t) {
    $first = reset($t);
    $remaining = array_shift($t);
    $output[$first] = $t;
}

echo '<pre>';
print_r($output);
$output=[];
foreach($t作为测试){
$first=重置($t);
$剩余=阵列移位($t);
$output[$first]=$t;
}
回声';
打印(输出);

只需在一个简单的循环中创建一个新数组……显示预期的输出。你想怎么做?CBroe,我考虑过这一点,但我不确定大型数据集的性能影响。Nithyanandhan M,很好的观点,补充了这个问题。只需在一个简单的循环中创建一个新数组……显示预期的输出。你们想怎么样?CBroe,我考虑过,但我不确定大型数据集的性能影响。Nithyanandhan M,很好的观点,补充了这个问题。