g_p_java Posted February 3, 2009 Share Posted February 3, 2009 Hi i would like to insert some values in the same array and i do: $arr_codes = array("0" => 'j'); $arr_codes = array("1" => 'a'); $arr_codes = array("2" => 'b'); $arr_codes = array("3" => 'c'); $arr_codes = array("4" => 'd'); $arr_codes = array("5" => 'e'); $arr_codes = array("6" => 'f'); $arr_codes = array("7" => 'g'); $arr_codes = array("8" => 'h'); $arr_codes = array("9" => 'i'); var_dump($arr_codes); The output i get is : array(1) { [9]=> string(1) "i" } count : , 0 it seems that every time i overwrite: what i have written before!!! What shall i correct in that? I guess, i shall use a for loop and "playing with indexes". like for ($i = 0; etc); May you please help me? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/143624-problem-with-var_dump-and-array/ Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 <?php $arr_codes = array(); $arr_codes["0"] = 'j'; $arr_codes["1"] = 'a'; //etc ?> Is how you would need to do it. Each time you are overwriting the other way. Link to comment https://forums.phpfreaks.com/topic/143624-problem-with-var_dump-and-array/#findComment-753576 Share on other sites More sharing options...
kenrbnsn Posted February 3, 2009 Share Posted February 3, 2009 Nice easy way of doing this: <?php $arr_codes = array_merge(array('j'),range('a','i')); echo '<pre>' . print_r($arr_codes,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/143624-problem-with-var_dump-and-array/#findComment-753578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.