array_diff() – Compare arrays for unique value differences

The “array_diff” php array function computes the difference of arrays.

Syntax:

      array_diff (array1,array2,array3.....)

In the above syntax "array1" is the array to be compare with the values of "array2", and display the difference as the result.

Example:

 <?php  
       $targetArray = array("amit","dhiren","baam","bks","Jessica"); 
      $compArray = array("bikas","dhiren","Jessica"); 
      $newArray = array_diff($targetArray, $compArray); 
      foreach ($newArray as $key => $value) {
        echo "$key =>$value "; 
}
?>

Ouptut:

  0 - amit
2 - baam
3 - bks

Similar Sites