0

For example, I want a function that returns me true for the following two inputs:

array('4','5','2') 
array('4','5','2')
0

3 Answers 3

1

You have a couple of options depending on what you want:

just use a straight if

 if($array === $array2)

or you can use array_diff which will give you an output array of any differences.

 $diff = array_diff($array, $array2)
Sign up to request clarification or add additional context in comments.

Comments

0

Yes, You can check that both arrays are the same or not using the array_diff function.

$a1=array("4","5","2");
$a2=array("4","5","2");

$result=array_diff($a1,$a2);
print_r($result);

If Both arrays are not the same than it will return difference else return a blank array.

1 Comment

Where is the condition - order is important?
0

If the 2 arrays are "identical", meaning that types are the same, than you can use the triple = comparison. If types are not identical, you could use the double = comparison.

$array1 = array('4', '5', '2');
$array2 = array('4', '5', '2');

var_dump($array1 == $array2); // true;
var_dump($array1 === $array2); // true;

VS

$array1 = array('4', '5', '2');
$array2 = array(4, 5, 2);

var_dump($array1 == $array2); // true;
var_dump($array1 === $array2); // false;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.