note 118930 added to language.operators.array

From: Date: Tue, 01 Mar 2016 10:15:17 +0000
Subject: note 118930 added to language.operators.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-205074@lists.php.net to get a copy of this message
If we want to make an array values only comparison we need to make a sort of each array in order to reset keys and sort all values in the same order. Here is an example: $a = array (0 => "apple", 1 => "banana"); $b = array (0 => "banana", 1 => "apple"); var_dump($a,$b); var_dump($a==$b); var_dump($a===$b); sort($a); sort($b); var_dump($a,$b); var_dump($a==$b); var_dump($a===$b); // Output array(2) { [0]=> string(5) "apple" [1]=> string(6) "banana" } array(2) { [0]=> string(6) "banana" [1]=> string(5) "apple" } bool(false) bool(false) array(2) { [0]=> string(5) "apple" [1]=> string(6) "banana" } array(2) { [0]=> string(5) "apple" [1]=> string(6) "banana" } bool(true) bool(true) ---- Server IP: 72.52.91.14 Probable Submitter: 80.90.95.34 ---- Manual Page -- http://php.net/manual/en/language.operators.array.php Edit -- https://master.php.net/note/edit/118930 Del: integrated -- https://master.php.net/note/delete/118930/integrated Del: useless -- https://master.php.net/note/delete/118930/useless Del: bad code -- https://master.php.net/note/delete/118930/bad+code Del: spam -- https://master.php.net/note/delete/118930/spam Del: non-english -- https://master.php.net/note/delete/118930/non-english Del: in docs -- https://master.php.net/note/delete/118930/in+docs Del: other reasons-- https://master.php.net/note/delete/118930 Reject -- https://master.php.net/note/reject/118930 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205074) next »