justcrapx Posted January 15, 2007 Share Posted January 15, 2007 can anyone tell me why does this:[code]<?php$arr = array();$a = 0;while($a < 5){$arr['$a'] = 10 + $a;$a++;echo $arr['$a'] . " - ";}echo "<br/>" . $arr[3];?>[/code]output this:10 - 11 - 12 - 13 - 14 - it does not print $arr[3], is there a syntax error? Link to comment https://forums.phpfreaks.com/topic/34332-need-a-hand-about-arrays/ Share on other sites More sharing options...
fert Posted January 15, 2007 Share Posted January 15, 2007 computers count up from zero Link to comment https://forums.phpfreaks.com/topic/34332-need-a-hand-about-arrays/#findComment-161526 Share on other sites More sharing options...
owenjh Posted January 15, 2007 Share Posted January 15, 2007 Try:[CODE]$arr = array();$a = 0;while($a < 5){$arr["$a"] = 10 + $a;echo $arr["$a"] . " - ";$a++;}echo "<br/>" . $arr[3];[/CODE] Link to comment https://forums.phpfreaks.com/topic/34332-need-a-hand-about-arrays/#findComment-161529 Share on other sites More sharing options...
justcrapx Posted January 15, 2007 Author Share Posted January 15, 2007 works fine, thanks Link to comment https://forums.phpfreaks.com/topic/34332-need-a-hand-about-arrays/#findComment-161538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.