php_joe Posted December 30, 2007 Share Posted December 30, 2007 Do leading zeros matter in array keys? is $var[04] the same as $var[4]? Link to comment https://forums.phpfreaks.com/topic/83752-solved-basic-array-key-question/ Share on other sites More sharing options...
hitman6003 Posted December 30, 2007 Share Posted December 30, 2007 They shouldn't matter unless they are passed as a string...e.g. : $var['04'] != $var[04] Link to comment https://forums.phpfreaks.com/topic/83752-solved-basic-array-key-question/#findComment-426123 Share on other sites More sharing options...
Barand Posted December 30, 2007 Share Posted December 30, 2007 Even if numeric they are not the same. <?php $a = array(); $a[010] = 'Hello'; $a[10] = 'World'; echo '<pre>', print_r($a, true), '</pre>'; ?> --> Array ( [8] => Hello // 010 is octal for 8 [10] => World ) [/pre} Link to comment https://forums.phpfreaks.com/topic/83752-solved-basic-array-key-question/#findComment-426127 Share on other sites More sharing options...
php_joe Posted December 30, 2007 Author Share Posted December 30, 2007 Even if numeric they are not the same. Hmm... in that case is there a function that strips leading zeros off of numbers? Link to comment https://forums.phpfreaks.com/topic/83752-solved-basic-array-key-question/#findComment-426130 Share on other sites More sharing options...
Barand Posted December 30, 2007 Share Posted December 30, 2007 intval() Link to comment https://forums.phpfreaks.com/topic/83752-solved-basic-array-key-question/#findComment-426134 Share on other sites More sharing options...
php_joe Posted December 30, 2007 Author Share Posted December 30, 2007 intval() Thank you Link to comment https://forums.phpfreaks.com/topic/83752-solved-basic-array-key-question/#findComment-426136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.