array diff assoc function in php count the difference

php example code : array_diff_assoc function in php - count the difference of arrays with index check

array-diff-assoc-example-in-php.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>php example code : array_diff_assoc function in php - count the difference of arrays with index check</title>
 </head>
 <body>
  <h3>php example code : array_diff_assoc function in php - count the difference of arrays with index check</h3>
  <?php
   /*
    ---------------------------------------------------------------
    let us make an array, with some keys and values
    ---------------------------------------------------------------
   */
   $myFirstArray = array('key1'=>10, 'key2'=>11, 'key3', 5);
   echo "<p>myFirstArray in the browser with structure</p>";
   echo "<pre>";
   print_r($myFirstArray);
   echo "</pre>";

   /*
    ---------------------------------------------------------------
    let us make another array, with some keys and values
    ---------------------------------------------------------------
   */
   $mySecondArray = array('key1'=>10, 'key2'=>12, 'key3'=>2, 5);
   echo "<p>mySecondArray in the browser with structure</p>";
   echo "<pre>";
   print_r($mySecondArray);
   echo "</pre>";
   
   $finalArray = array_diff_assoc($myFirstArray, $mySecondArray);
   echo "<p style='background:#ccc; color:red;'>Output of final array using array_diff_assoc function</p>";
   echo "<pre>";
   print_r($finalArray);
   echo "</pre>";
   /*
    ----------------------------------------------------------------------------------------------------
    1. [key2], is different in both arrays thus it will come in the final array
    2. [0] => key3, the value key3 got a key 0 and it's also different
    3. [1] => 5, the value 5 got a key 1 and it's also different in the second array which got a key 0
    ----------------------------------------------------------------------------------------------------
   */
  ?>
 </body>
</html>

php example code : array_diff_assoc function in php - count the difference of arrays with index check - output in the browser

No comments:

Post a Comment

leave your comments here..