|
|
Difference between two arraysWe can find out difference of two arrays by using array_diff function. This function takes two arrays as input and then returns the result array. Syntax of this function is here.
$new_array = array_diff ($array1, $array2);
For example let us use one array a1 and store text entered by user in a web form after converting the text string to an array. Now to prevent spammers posting URL or posting of some bad words we will develop another array a2 where all negative words we will store. These words we don't want to be present in the first ( a1) array.
Here is the example of how the array_diff works
$a1=array("first", "second", "third","fourth","fifth");
$a2=array("second","fourth","sixth");
$new_array=array_diff($a1,$a2);
while (list ($key, $val) = each ($new_array)) {
echo "$key -> $val <br>";
}
The output of above code will be
0 -> first
2 -> third
4 -> fifth
| |
| | MAZHAR HUSSAIN | 08-08-2010 |
|---|
| PLEASE SEND ME SIR!DIFFERENCE BETWEEN FUNCTION AND ARRAY? |
|
|
|
|
|
|