note 116985 added to function.array-keys

From: Date: Mon, 30 Mar 2015 16:31:57 +0000
Subject: note 116985 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-202085@lists.php.net to get a copy of this message
It is worth noting that array_keys does not maintain the data-type of the keys when mapping them to a new array. This created an issue with in_array and doing a lookup on characters from a string. NOTE: my lookup $array has a full map of numbers and characters - upper and lower - to do an simple faux encryption with. <?php $array = array( 'e' => 'ieio' ,'1' => 'one' ,'2' => 'two' ,'0' => 'zero' ); var_dump($array); $keys = array_keys($array); var_dump($keys); $string = '1e0'; for ($i = 0; $i < strlen($string); $i++) { if (in_array($string[$i],$keys,'strict')) echo 'dude '; else echo 'sweet '; } ?> Outputs: array (size=4) 'e' => string 'ieio' (length=4) 1 => string 'one' (length=3) 2 => string 'two' (length=3) 0 => string 'zero' (length=4) array (size=4) 0 => string 'e' (length=1) 1 => int 1 2 => int 2 3 => int 0 sweet dude sweet ---- expected to see: dude dude dude ---- Server IP: 72.52.91.14 Probable Submitter: 67.53.162.218 ---- Manual Page -- http://php.net/manual/en/function.array-keys.php Edit -- https://master.php.net/note/edit/116985 Del: integrated -- https://master.php.net/note/delete/116985/integrated Del: useless -- https://master.php.net/note/delete/116985/useless Del: bad code -- https://master.php.net/note/delete/116985/bad+code Del: spam -- https://master.php.net/note/delete/116985/spam Del: non-english -- https://master.php.net/note/delete/116985/non-english Del: in docs -- https://master.php.net/note/delete/116985/in+docs Del: other reasons-- https://master.php.net/note/delete/116985 Reject -- https://master.php.net/note/reject/116985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202085) next »