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

3
  • 4
    just apply array_values to $lol to effectively reset the keys Commented Sep 18, 2018 at 9:40
  • @Ghost thank you, solved sir why i can't voted up your question by the way ? Commented Sep 18, 2018 at 9:42
  • this is a comment box, sure glad this helped Commented Sep 18, 2018 at 9:51

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

sort($lol);

var_dump($lol);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.