且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP json_decode

更新时间:2023-12-04 14:01:40

如何比较不存在的数组字段?

How can you compare non-existing array fields?

没有$ num ['b']字段,有这些字段,其数组[4] (index 0..3)

there is no $num['b'] field, there are these fields, its array[4] (index 0..3)

  • a:1
  • a:2
  • a:3
  • b:2

$num在第一次迭代中将保持不变

$num in first iteration will hold

array("a"=>1);

因此,如果您想与"b":2进行比较,则必须使用以下模式:

so if you wanna compare to "b":2 you have to use this pattern:

$cmpr = array_shift($json);
...
if($num != $cmpr)

Array_shift: http://php.net/manual/zh/function. array-shift.php

Array_shift : http://php.net/manual/en/function.array-shift.php