Jefsama Jefsama - 4 months ago 20
PHP Question

Php array_intersect output

i'm having trouble with how array works.

$a = array("24","33","12");
$b = array("24","12");

$c = array_intersect($a,$b);

echo json_encode($c);

// {"0":"24","2":"12"}


I expect the output to be like this:

// ["24","12"]


How can i achieve that output?

Answer
echo json_encode(array_values($c));

output

["24","12"]
Comments