我有两个应该相等的数组。
当 var 转储并断言它们是否相等时,我得到以下输出
array(2) {
[0]=>
array(3) {
["100"]=> //notice that the key is NOT numeric
int(0)
["strKey1"]=>
int(0)
["strKey2"]=>
int(0)
}
[1]=>
array(3) {
["100"]=> //notice that the key is NOT numeric
int(0)
["strKey1"]=>
int(0)
["strKey2"]=>
int(0)
}
}
There was 1 failure:
1) Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- '100' => 0
'strKey1' => 0
'strKey2' => 0
+ '100' => 0
)
两个数组的简单 foreach 循环将键再次映射为数字,工作正常,但不是测试中最漂亮的 hack。
$actualArray = array();
foreach ($actualOriginal as $key => $value) {
$actualArray[$key] = $value;
}
$expectedArray = array();
foreach ($expectedOriginal as $key => $value) {
$expectedArray[$key] = $value;
}
有什么建议为什么这些数组不被认为是平等的?
谢谢你的帮助!