php数组\列函数,如何使用索引\键

php数组\列函数,如何使用索引\键,php,function,Php,Function,我正在使用php函数 $array = [ 'red' => ['nice' => true, 'hot' => true], 'green => ['nice' => true, 'hot' => false ] array array_column ( array $array , mixed $column_key [, mixed $index_key = null ] ) 我想把index_键设置为数组索引,怎么做 array_column($a

我正在使用php函数

$array = [ 'red' => ['nice' => true, 'hot' => true], 'green => ['nice' => true, 'hot' => false ]

array array_column ( array $array , mixed $column_key [, mixed $index_key = null ] )
我想把index_键设置为数组索引,怎么做

array_column($array, 'hot' , index??? )
得到

 [  
     'red' => true,
     'green' => false
 ]
array_column()允许您将子数组中的元素定义为键,而不是子数组的键;它使用子数组中的值

不过,您可以做的是:

$result = array_combine(
    array_keys($originalArray),
    array_column($originalArray, 'hot')
);
array_column()允许您将子数组中的元素定义为键,而不是子数组的键;它使用子数组中的值

不过,您可以做的是:

$result = array_combine(
    array_keys($originalArray),
    array_column($originalArray, 'hot')
);