note 112196 deleted from function.array-merge by cmb

From: Date: Mon, 28 Jan 2019 14:27:03 +0000
Subject: note 112196 deleted from function.array-merge by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210124@lists.php.net to get a copy of this message
Note Submitter: Janez R. ---- Please note that -1 is a numeric key and will be reindexed. Less obvious numeric keys are also '-1' (becomes -1) and -1.5 (becomes -1). '-1a', however, is not a numeric key and you could exploit the fact that '-1a' == -1 evaluates to true in php (just a hint). But as this is not very efficient, operator + may be a better option. <?php $arr = array(-1=> "-1", '-2'=> "'-2'", -3.5=> "-3.5", '-4a'=> "'-4a'"); print_r(array( $arr, array_merge($arr,array()), '-1a' == -1, )); ?> Result: Array ( [0] => Array ( [-1] => -1 [-2] => '-2' [-3] => -3.5 [-4a] => '-4a' ) [1] => Array ( [0] => -1 [1] => '-2' [2] => -3.5 [-4a] => '-4a' ) [2] => 1 )

« previous php.notes (#210124) next »