<?php if (‘ab‘>‘b‘) { echo a; } else { echo b; } ?>
结果为 b;
然后看代码 :
<?php function key_compare_func($key1, $key2) { if ($key1 == $key2) return 0; else if ($key1 > $key2) return 1; else return -1; } $array1 = array(‘blue‘ => 1, ‘red‘ => 2, ‘green‘ => 3, ‘purple‘ => 4); $array2 = array(‘green‘ => 5, ‘blue‘ => 6, ‘yellow‘ => 7, ‘cyan‘ => 8); var_dump(array_diff_ukey($array1, $array2, ‘key_compare_func‘)); ?>
结果:
array(2) { ["red"]=> int(2) ["purple"]=> int(4) }
然后改动:
<?php function key_compare_func($key1, $key2) { if ($key1 == $key2) return 1; else if ($key1 > $key2) return 0; else return -1; } $array1 = array(‘blue‘ => 1, ‘red‘ => 2, ‘green‘ => 3, ‘purple‘ => 4); $array2 = array(‘green‘ => 5, ‘blue‘ => 6, ‘yellow‘ => 7, ‘cyan‘ => 8); var_dump(array_diff_ukey($array1, $array2, ‘key_compare_func‘)); ?>
结果:
array(1) { ["blue"]=> int(1) }
很容易理解了
时间: 2024-10-08 13:02:39