Q:

How to compare two array values in PHP

0

How to compare two array values in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP array_diff() function

You can use the PHP array_diff() function to compare an array against one or more other arrays.

The array_diff() function returns the values in the first array that are not present in any of the other arrays. Let's try out an example to understand how it actually works:

<?php
$array1 = array("a" => "sky", "star", "moon", "cloud", "moon");
$array2 = array("b" => "sky", "sun", "moon");
 
// Comparing the values
$result = array_diff($array1, $array2);
print_r($result);
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to calculate the sum of values in an array in ... >>
<< How to randomize the order of an array in PHP...