简体   繁体   中英

array_diff is not giving expected results

I have 2 array var_dump of these two array is as below

array
  0 => int 1
  1 => int 2
  2 => int 3
  3 => int 4
  4 => int 5
  5 => int 6
  6 => int 7
  7 => int 8
  8 => int 9
  9 => int 10
  10 => int 11
  11 => int 12
array
  0 => string '10' (length=2)
  1 => string '6' (length=1)
  2 => string '4' (length=1)
  3 => string '11' (length=2)
  4 => string '12' (length=2)
  5 => string '7' (length=1)
  6 => string '9' (length=1)
  7 => string '5' (length=1)
  8 => string '8' (length=1)
  9 => string '1' (length=1)
  10 => string '2' (length=1)

when i used $arr_valid = array_diff($arr,$room_already_book); Then i get null result but it should give me result 3.This is work fine when diff is more than one elements

That might be because: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM