php example code : array_diff function in php - counts the difference of arrays
array-diff-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 function in php - counts the difference of arrays</title>
</head>
<body>
<h3>php example code : array_diff function in php - counts the difference of arrays</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($myFirstArray, $mySecondArray);
echo "<p style='background:#cccccc; font-weight:bold;'>Output of final array using array_diff function</p>";
echo "<pre>";
print_r($finalArray);
echo "</pre>";
/*
-----------------------------------------------------------------
both keys([key2],[0]) are common and different in values thus
array_diff returns them.
-----------------------------------------------------------------
*/
?>
</body>
</html>

Please write down with regular expression.
ReplyDeleteIt is badly need to every one.
thnQ anowar vhi.
ReplyDeletethis post has been dedicated to you and it's a symbol of inspiration and integrity of visitor's comment.