Carlos Jhon manlulu Carlos Jhon manlulu - 4 months ago 23
PHP Question

Array Difference from Database

In

$imeiserial
I have
123,222,333
in
$imeitransferserial
I have
123,222
. I just want to show the value of the difference between those 2 array, I use this code but it give me error:
Array to string conversion
what did I do wrong? or I need more conversion in this function?

$imei=$row["IMEI_MX"];
$imeiserial = explode(',', $imei);
$imeitransfer=$row2["IMEI_MX"];
$imeitransferserial = explode(',', $imeitransfer);

$a1=array($imeiserial);
$a2=array($imeitransferserial);

$result= array_diff_assoc($a1,$a2);

Answer

That $a1 = array assignment is superfluous. Just leave it:

$a1 = $imeiserial; // no need to put inside an array
$a2 = $imeitransferserial; // once exploded, they are already an array

And using *_assoc flavor doesn't make sense, your keys are numeric, just use array_diff:

$result = array_diff($a1,$a2);