CodeIgniter Forums
Desires and elegant foreach for a messy array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Desires and elegant foreach for a messy array (/showthread.php?tid=48963)



Desires and elegant foreach for a messy array - El Forum - 02-02-2012

[eluser]pdxbenjamin[/eluser]
My array looks something like this...
Code:
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

When I foreach through them I get...
Code:
1
2
3
4
5

That isn't my problem, what I have is an update running at the end of each iteration.
Code:
1
<- UPDATE
2
<- UPDATE
3
<- UPDATE
4
<- UPDATE
5
<- UPDATE

How do I make it a collective so I can format the string, and make one Update.
I'd like to have the final result. 1, 2, 3, 4, 5



Thanks.


Desires and elegant foreach for a messy array - El Forum - 02-02-2012

[eluser]jmadsen[/eluser]
assuming you want to build an sql IN clause?

Look at http://php.net/manual/en/function.implode.php


Desires and elegant foreach for a messy array - El Forum - 02-02-2012

[eluser]pdxbenjamin[/eluser]
Yes, thank you that's what I needed.