我有一个多维数组,每个子数组都具有相同的键,但它们的值大多不同。而且我需要知道此数组中的每个id子项是否具有相同的值。只需返回true或false。
array(
0 => array(
'id' = 123,
'key1' = 'abcd',
...),
1 => array(
'id' = 123,
'key1' = 'efgh',
...),
2 => array(
'id' = 123,
'key1' = 'ijkl',
...)
)
如果是上述情况,则返回true。谢谢,SFE(对不起,英语)。
您可以使用此功能来实现此参考:http : //php.net/manual/zh/function.array-column.php
<?php
//get the same column values
$sameColumns = array_column($array, 'id');
//find the unique values
$sameColumns = array_unique($sameColumns);
//check the count
if(count($sameColumns) == 1){
return true;
}
//return status
return false;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句