array going backwards

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

array going backwards

Post by shiznatix »

ok I have a array like this

Code: Select all

[0] => username=bogus
[1] => channel => default
[2] =>
[3] => id=term_funk_soul
[4] => username=soul
[5] => number=soul
[6] => channel => outgoing_funk
and what I need to do is find the channel name thing and put it at the top of the section that it belongs to like this

Code: Select all

[0] => The channel is 'Default'
[1] => username=bogus
[2] => channel => default
[3] =>
[4] => The channel is 'outgoing_funk'
[5] => id=term_funk_soul
[6] => username=soul
[7] => number=soul
[8] => channel => outgoing_funk
I am having a rough time with this logic, any help?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

There's a couple of ways of doing that. First, and logically simplest, would be to break the array into a set of arrays, add the new elements, and then merge them back into being a big array..

Alternatively, you'll end up playing with array_splice() to add new elements. Tricky.

I'd break it up and then rebuild it personally .. unless it's massive.
Post Reply