我使用下面的代码来获取localJSON中未包含的uploadedJSON数组。
$uploadedJSON = json_decode(file_get_contents('php://input'),true);
$data = file_get_contents('results.json');
$localJSON = json_decode($data,true);
$result = array_diff($uploadedJSON, $localJSON);
我上传的JSON如下:
Array
(
[0] => Array
(
[shop] => OTCI
[iPadNumber] => 1
[startTime] => 03 03 14
[endTime] => 04 04 14
[elapsedTime] => 54
[amount] => 15
[receipt] => 0
[staffID] => 123456789
)
[1] => Array
(
[shop] => OTCI
[iPadNumber] => 1
[startTime] => 03 03 14
[endTime] => 04 04 14
[elapsedTime] => 54
[amount] => 15
[receipt] => 1
[staffID] => 123456789
)
)
我的$ localJSON如下:
Array
(
[0] => Array
(
[shop] => OTCI
[iPadNumber] => 1
[startTime] => 03 03 14
[endTime] => 04 04 14
[elapsedTime] => 54
[amount] => 15
[receipt] => 1111
[staffID] => 123456789
)
[1] => Array
(
[shop] => OTCI
[iPadNumber] => 1
[startTime] => 03 03 14
[endTime] => 04 04 14
[elapsedTime] => 54
[amount] => 15
[receipt] => 2222
[staffID] => 123456789
)
[2] => Array
(
[shop] => OTCI
[iPadNumber] => 1
[startTime] => 03 03 14
[endTime] => 04 04 14
[elapsedTime] => 54
[amount] => 15
[receipt] => 3333
[staffID] => 123456789
)
)
差别不算什么。我怎样才能获得localJSON中未包含在localJSON中的数组。
提前致谢,
答案 0 :(得分:0)
此函数仅检查n维数组的一维。当然,您可以使用array_diff($ array1 [0],$ array2 [0]);来检查更深的维度。
<强> SOURCE 强>
您很可能需要创建一个for循环,为您的二维数组调用array_dif()
方法。