array_diff遇到的坑

一维数组求差集 key值不能变化

比如

$a = ['01', '12'];
$b = ['01', '02', '03', ....,'13']
$c = array_diff($b,$a));
返回的结果为
array (size=11)
  1 => string '02' (length=2)
  2 => string '03' (length=2)
  3 => string '04' (length=2)
  4 => string '05' (length=2)
  5 => string '06' (length=2)
  6 => string '07' (length=2)
  7 => string '08' (length=2)
  8 => string '09' (length=2)
  9 => string '10' (length=2)
  10 => string '11' (length=2)
  12 => string '13' (length=2)

  

 只取值的话需要加上

array_values($c)

 

posted @ 2020-10-14 18:15  pengcx  阅读(249)  评论(0编辑  收藏  举报