我的方法是这样的:
<code><?php $a = [ [ 'id' => 33, // 这里的键名不固定 'name' => 'aaa', ], [ 'id' => 22, 'name' => 'bbb' ] ]; $dat = []; foreach ($a as $b) { list($k, $v) = array_values($b); $dat[$k] = $v; } var_export($dat); // 输出:array ( 33 => 'aaa', 22 => 'bbb', ) </code>
我的方法是这样的:
<code><?php $a = [ [ 'id' => 33, // 这里的键名不固定 'name' => 'aaa', ], [ 'id' => 22, 'name' => 'bbb' ] ]; $dat = []; foreach ($a as $b) { list($k, $v) = array_values($b); $dat[$k] = $v; } var_export($dat); // 输出:array ( 33 => 'aaa', 22 => 'bbb', ) </code>
http://php.net/manual/zh/function.array-column.php