0

i have array like this

$arrA = array(0 => 0, 1=>1, 2=>2 );

and

$arrB = array(0 => "0", 1 => "1"); 

and i search difference the array with

$lol = array_diff($arrA, $arrB);
var_dump($lol);

but the output of key array start from 2 not from 0 like this :

array(1) {
  [2]=>
  string(1) "2"
}

my question is how to change key of the array in variable $lol to 0(zero) again ?

thank you

2 Answers2

0

Hey use array_values() function on your output.

$arrA = array(0 => 0, 1=>1, 2=>2 );
$arrB = array(0 => "0", 1 => "1");

$lol = array_values(array_diff($arrA, $arrB));
var_dump($lol);
Gajanan Kolpuke
  • 155
  • 1
  • 1
  • 14
0

If you want the result begins with zero, just sort it before output.

sort($lol);

var_dump($lol);
treyBake
  • 6,440
  • 6
  • 26
  • 57
Dng
  • 121
  • 6