![]() |
Can you build an array with a for loop - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html) +--- Thread: Can you build an array with a for loop (/thread-53773.html) |
Can you build an array with a for loop - El Forum - 08-08-2012 [eluser]ppwalks[/eluser] I am trying to build an array to insert into db, I have a count and want to build the array according to the count so used a for loop, except it is only showing the last result of the array so could someone help with this please. Code: $count = count($_POST['cat_id']); The ouput to screen is: ( [7] => 126 ) when it should start from 1 and increment to 7 as a for loop should, where am i going wrong Can you build an array with a for loop - El Forum - 08-08-2012 [eluser]TWP Marketing[/eluser] [quote author="ppwalks" date="1344447239"]I am trying to build an array to insert into db, I have a count and want to build the array according to the count so used a for loop, except it is only showing the last result of the array so could someone help with this please. Code: $count = count($_POST['cat_id']); The ouput to screen is: ( [7] => 126 ) when it should start from 1 and increment to 7 as a for loop should, where am i going wrong[/quote] You are overwriting the array on each loop. Try this: Code: $count = count($_POST['cat_id']); Also your counter $i starts at 1, while an array index can/should start at zero Can you build an array with a for loop - El Forum - 08-08-2012 [eluser]ppwalks[/eluser] Superb Pal, thanks a bunch.. |