我有這個代碼在$ array1中尋找$ array2。PHP - 不帶循環的小寫多維數組
我的問題是,我需要小寫兩個數組,以便in_array匹配工作,並且此代碼按預期方式運行,但$ array1大於20k對象 - 是否有小寫而不丟失數組結構和循環?
$array1 = array(code => 200, status => success,
array(
'email' => '[email protected]',
'status' => 'Pending'
),
array(
'email' => '[email protected]',
'status' => 'Approved: Printed & Cleared'
),
array(
'email' => '[email protected]',
'status' => 'Approved'
),
array(
'email' => '[email protected]',
'status' => 'Approved: Printed & Cleared'
),
);
$yourArray = array();
$array = array();
foreach ($array1 as &$array){
$yourArray[] = array_map('strtolower', $array);
}
echo "<pre>"; print_r($yourArray);
$array2 = array(
'email' => '[email protected]',
'status' => 'Pending'
);
$yourArray2 = array_map('strtolower', $array2);
if(in_array($yourArray2 , $yourArray)) {
echo "match";
} else {
echo "no match";
}
echo "<pre>"; print_r($yourArray2);
注意,'array_walk'和'array_walk_recursive'既可以做到這一點 – Machavity