Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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_Array Merge - Fatal编程技术网

php:如何从数组中提取数据

php:如何从数组中提取数据,php,array-merge,Php,Array Merge,在对2个sql查询进行数组合并后,我得到了如下数组: 数组:4[? 0=>数组:1[? “错误”=>“1” ] 1=>数组:1[? “错误”=>“5” ] 2=>数组:1[? “错误”=>“1” ] 3=>数组:1[? “错误”=>“11” ] ]如果需要输出为3 <?php $array_merge = [ [ "mistake" => "1"], [ "mistake" => "5"], [ "mistake" => "1"], [

在对2个sql查询进行数组合并后,我得到了如下数组:

数组:4[?
0=>数组:1[?
“错误”=>“1”
]
1=>数组:1[?
“错误”=>“5”
]
2=>数组:1[?
“错误”=>“1”
]
3=>数组:1[?
“错误”=>“11”
]

]
如果需要输出为3

<?php
$array_merge = [
    [ "mistake" => "1"],
    [ "mistake" => "5"],
    [ "mistake" => "1"],
    [ "mistake" => "11"],
];
$temp = array_unique(array_column($array_merge, 'mistake'));
echo count($temp);
?>

工作演示:

您需要输出为3
<?php
$array_merge = [
    [ "mistake" => "1"],
    [ "mistake" => "5"],
    [ "mistake" => "1"],
    [ "mistake" => "11"],
];
$temp = array_unique(array_column($array_merge, 'mistake'));
echo count($temp);
?>