Answer by AlexisAmasis for PHP compare array
I just wanted to contribute that:echo var_export([1 => 2, 0 => 1, 3] == [1, 2, 3], 1);Echoes true. Therefore the == operator does not check that the elements in the array are in the same order,...
View ArticleAnswer by Ibnul Husainan for PHP compare array
this is a simple way to get the difference:$array1 = [40,10,30,20,50];$array2 = [10,30];$result = array_filter( $array1, function($var) use($array2){ if(in_array($var, $array2)){ return $var; } }...
View ArticleAnswer by revoke for PHP compare array
If you want to search some array inside a big array of arrays (>10k) then much more quickly is comparing serialized arrays (saved in cache). Example from work with URL:/**@return array*/function...
View ArticleAnswer by Case for PHP compare array
If you do not care about keys and that just the values then this is the best method to compare values and make sure the duplicates are counted.$mag = '{"1":"1","2":"2","3":"3","4":"3"}';$mag_evo =...
View ArticleAnswer by Murz for PHP compare array
Also you can try this way:if(serialize($a1) == serialize($a2))
View ArticleAnswer by CJ Ramki for PHP compare array
get the array from user or input the array values.Use sort function to sort both arrays. check using ternary operator. If the both arrays are equal it will print arrays are equal else it will print...
View ArticleAnswer by hakre for PHP compare array
Comparing two arrays to have equal values (duplicated or not, type-juggling taking into account) can be done by using array_diff() into both directions:!array_diff($a, $b) && !array_diff($b,...
View ArticleAnswer by 1Rhino for PHP compare array
Compare values of two arrays:$a = array(1,2,3);$b = array(1,3,2);if (array_diff($a, $b) || array_diff($b, $a)) { echo 'Not equal';}else{ echo 'Equal';}
View ArticleAnswer by rcourtna for PHP compare array
verify that the intersections count is the same as both source arrays$intersections = array_intersect($a1, $a2);$equality = (count($a1) == count($a2)) && (count($a2) == count($intersections)) ?...
View ArticleAnswer by Tyron for PHP compare array
Conclusion from the commentary here:Comparison of array values being equal (after type juggling) and in the same order only:array_values($a1) == array_values($a2)Comparison of array values being equal...
View ArticleAnswer by pnomolos for PHP compare array
As far as I can tell, there isn't a single built-in function that'll do it for you, however, something like:if (count($a) == count($b) && (!count(array_diff($a, $b))) { // The arrays are the...
View ArticleAnswer by chichilatte for PHP compare array
A speedy method for comparing array values which can be in any order...function arrays_are_same($array1, $array2) { sort($array1); sort($array2); return $array1==$array2;}So for... $array1 =...
View ArticleAnswer by Chintan for PHP compare array
try this :$array1 = array("street" => array("Althan"), "city" => "surat", "state" => "guj", "county" => "india"); $array2 = array("street" => array("Althan"), "city" => "surat",...
View ArticleAnswer by pscheit for PHP compare array
@Cleanshooter i'm sorry but this does not do, what it is expected todo: (so does array_diff mentioned in this context)$a1 = array('one','two');$a2 =...
View ArticleAnswer by moonw for PHP compare array
array_intersect() returns an array containing all the common values.
View ArticleAnswer by aukion for PHP compare array
if(count($a1) == count($a2)){ $result= array_intersect($a1, $a2); if(count($a1) == count($result)) echo 'the same'; else echo 'a1 different than a2';} else echo 'a1 different than a2';
View ArticleAnswer by Alan Haggai Alavi for PHP compare array
if ( $a == $b ) { echo 'We are the same!';}
View ArticleAnswer by Alex Martelli for PHP compare array
Just check $a1 == $a2 -- what's wrong with that?
View ArticlePHP compare array
Is there anyway to compare arrays in php using an inbuilt function, short of doing some sort of loop?$a1 = array(1,2,3);$a2 = array(1,2,3);if (array_are_same($a1, $a2)) { // code here}Btw, the array...
View Article
More Pages to Explore .....