note 124711 added to book.array

From: Date: Wed, 12 Feb 2020 20:34:02 +0000
Subject: note 124711 added to book.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-214084@lists.php.net to get a copy of this message
Using null as the key when setting an array value is NOT the same as using empty []. <?php $null = null; $testArray = []; $testArray[$null] = 1; $testArray[$null] = 2; $testArray[$null] = 3; $testArray[$null] = 4; var_dump($testArray); ?> Output: array(1) { '' => int(4) } <?php $testArray = []; $testArray[null] = 1; $testArray[null] = 2; $testArray[null] = 3; $testArray[null] = 4; var_dump($testArray); ?> Output: array(1) { '' => int(4) } <?php $testArray = []; $testArray[] = 1; $testArray[] = 2; $testArray[] = 3; $testArray[] = 4; var_dump($testArray); ?> Output: array(4) { [0] => int(1) [1] => int(2) [2] => int(3) [3] => int(4) } ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 167.232.252.15) ---- Manual Page -- http://php.net/manual/en/book.array.php Edit -- https://master.php.net/note/edit/124711 Del: integrated -- https://master.php.net/note/delete/124711/integrated Del: useless -- https://master.php.net/note/delete/124711/useless Del: bad code -- https://master.php.net/note/delete/124711/bad+code Del: spam -- https://master.php.net/note/delete/124711/spam Del: non-english -- https://master.php.net/note/delete/124711/non-english Del: in docs -- https://master.php.net/note/delete/124711/in+docs Del: other reasons-- https://master.php.net/note/delete/124711 Reject -- https://master.php.net/note/reject/124711 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214084) next »