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

how will i implode the result of array_diff


How will i separated by comma the result of array_diff i tried this code but it gave me Warning: explode() expects parameter 2 to be string, array give
Warning: Invalid argument supplied for foreach()


<?php
$row['IMEI_MX'] = '123,222,333';
$row2["IMEI_MX"] = '123,222';
$imei = $row["IMEI_MX"];
$imeiserial = explode(',', $imei);
$imeitransfer = $row2["IMEI_MX"];
$imeitransferserial = explode(',', $imeitransfer);

$a1 = $imeiserial;
$a2 = $imeitransferserial;

$result = array_diff($a1,$a2);
$separate = implode(' ', $result);
foreach($separate as $is){

echo $is;

}

Answer

I think you just want to show the values of first string which are not in second string .

Tried this one

    <?php
    $row['IMEI_MX'] = '123,222,333,444';
    $row2["IMEI_MX"] = '123,222';
    $imei = $row["IMEI_MX"];
    $imeiserial = explode(',', $imei);
    $imeitransfer = $row2["IMEI_MX"];
    $imeitransferserial = explode(',', $imeitransfer);

    $a1 = $imeiserial;
     $a2 = $imeitransferserial;

    $result = array_diff($a1,$a2);
  $sting = implode(',',$result);
   echo  $sting;
?>

It will result as

333,444
Comments