note 121907 added to language.operators.comparison

From: Date: Thu, 23 Nov 2017 12:16:51 +0000
Subject: note 121907 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-209206@lists.php.net to get a copy of this message
Care must be taken when using the spaceship operator with arrays that do not have the same keys: - Contrary to the notes above ("Example #2 Transcription of standard array comparison"), it does *not* return null if the left-hand array contains a key that the right-hand array does not. - Because of this, the result depends on the order you do the comparison in. For example: <?php $a = ['a' => 1, 'b' => 2, 'c' => 3, 'e' => 4]; $b = ['a' => 1, 'b' => 2, 'd' => 3, 'e' => 4]; var_dump($a <=> $b); // int(1) : $a > $b because $a has the 'c' key and $b doesn't. var_dump($b <=> $a); // int(1) : $b > $a because $b has the 'd' key and $a doesn't. ?> ---- Server IP: 208.43.231.9 Probable Submitter: 213.105.83.130 ---- Manual Page -- http://php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/121907 Del: integrated -- https://master.php.net/note/delete/121907/integrated Del: useless -- https://master.php.net/note/delete/121907/useless Del: bad code -- https://master.php.net/note/delete/121907/bad+code Del: spam -- https://master.php.net/note/delete/121907/spam Del: non-english -- https://master.php.net/note/delete/121907/non-english Del: in docs -- https://master.php.net/note/delete/121907/in+docs Del: other reasons-- https://master.php.net/note/delete/121907 Reject -- https://master.php.net/note/reject/121907 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209206) next »