我有2個相同的PHP數組。只有一個值不同。我想找到這個值:PHP array_diff:奇怪的行爲
var_dump(array_diff(array(
"a" => "1",
"b" => "SomeString",
"c" => 1, // <- different value, same key
"d" => "4521",
"e" => "7546654241",
"f" => "78",
"g" => "99.999",
"h" => "34",
"i" => "http://google.com/"
), array(
"a" => "1",
"b" => "SomeString",
"c" => "0", // <- different value, same key
"d" => "4521",
"e" => "7546654241",
"f" => "78",
"g" => "99.999",
"h" => "34",
"i" => "http://google.com/"
)));
結果是array(0) { }
但應該有新的"c"
價值,但並非如此。當我刪除所有其他值:
var_dump(array_diff(array(
"c" => 1
), array(
"c" => "0"
)));
我得到了我想要array(1) { ["c"]=> int(1) }
。
我沒有低估它。爲什麼這樣?
也許這會對你更好http://php.net/manual/en/function.array-diff-assoc.php – RST 2014-08-28 16:41:02