note 129841 added to language.operators.array

From: Date: Thu, 07 Nov 2024 09:32:53 +0000
Subject: note 129841 added to language.operators.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-221636@lists.php.net to get a copy of this message
In the example <?php $a = array("apple", "banana"); $b = array(1 => "banana", "0" => "apple"); var_dump($a == $b); // bool(true) var_dump($a === $b); // bool(false) ?> You might think the expression returns false because the type of the key 0 is a string. However, this is not the case. Here, the expression returns false because the order of the elements is wrong. ie. <?php $b = array(1 => "banana", 0 => "apple"); $b = array(1 => "banana", "0" => "apple"); var_dump($a == $b); // bool(true) var_dump($a === $b); // bool(true) ?> If you want to understand how the type checking works, This example showcases the behavior. <?php $a = array(0 => 1.0, 1 => 2.0); $b = array(0 => "1.0", 1 => "2.0"); var_dump($a == $b); // bool(true) var_dump($a === $b); // bool(false) ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 94.204.154.122) ---- Manual Page -- https://php.net/manual/en/language.operators.array.php Edit -- https://main.php.net/note/edit/129841 Del: integrated -- https://main.php.net/note/delete/129841/integrated Del: useless -- https://main.php.net/note/delete/129841/useless Del: bad code -- https://main.php.net/note/delete/129841/bad+code Del: spam -- https://main.php.net/note/delete/129841/spam Del: non-english -- https://main.php.net/note/delete/129841/non-english Del: in docs -- https://main.php.net/note/delete/129841/in+docs Del: other reasons-- https://main.php.net/note/delete/129841 Reject -- https://main.php.net/note/reject/129841 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221636) next »