For example, I want a function that returns me true for the following two inputs:
array('4','5','2')
array('4','5','2')
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)
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.
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;