Geting this value to the beginning of an array....

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
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Geting this value to the beginning of an array....

Post by neophyte »

I have an array like this:

Array
(
[Rocky Mountain] => Rocky Mountain
[Northeastern] => Northeastern
[Southeastern] => Southeastern
[Midwestern] => Midwestern
[Northwestern] => Northwestern
[Southwestern/Gulf States] => Southwestern
[Western] => Western
[Camp Information] => Camp Information // I'd like this element to be at the top of the list...
)

I'd like the Camp Information key to be at the top of the list and I'm not sure how to do it....

Below is how the 'camp information' is being added to the array...

Code: Select all

<?php
foreach ($temp['selected'] as $key => $val )
{
$temp['option'][$key] = $val; //$temp['option'] is already an array
}

?>
I've tried array_unshift. But the val outputs as 'array'...

I'm not sure how to do this?

Any ideas?

Thanks
Last edited by neophyte on Wed Dec 22, 2004 4:54 pm, edited 1 time in total.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

push and pop?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Those seem to be for adding and removing items at the end of the array. I'm trying to get this one at the top/beginning of the array.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

shift and unshift
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

[php_man]array_unshift[/php_man]() should do it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply