RE: [PHP] Changing order of just one array item?

From: Date: Sun, 19 Jan 2003 02:44:22 +0000
Subject: RE: [PHP] Changing order of just one array item?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132156@lists.php.net to get a copy of this message
This would do it: <?php $first[] = 'hello'; $first[] = 'bye'; function swap(&$list, $first, $second) { $tempOne = $list[$first]; $list[$first] = $list[$second]; $list[$second] = $tempOne; } swap($first, 0, 1); print_r($first); ?> Timothy Hitchens (HiTCHO) Open Source Consulting e-mail: tim@hitcho.com.au > -----Original Message----- > From: Leif K-Brooks [mailto:eurleif@buyer-brokerage.com] > Sent: Sunday, 19 January 2003 12:36 PM > To: php-general@lists.php.net > Subject: [PHP] Changing order of just one array item? > > > I need to change where one item is ordered in an array. I > know how to > sory an array, but I need to move one item up/down in the > array. Example: $array is: 0 => "element one" 1 => "element > two" 2 => "element three" 3 => "element four" I call > array_order_up($array[1]) and $array is now: 0 => "element > one" 2 => "element three" 1 => "element two" 3 => > "element four" > > If there aren't any native functions to do this, can anyone > think of a > way to make my own function to do this? > > -- > The above message is encrypted with double rot13 encoding. > Any unauthorized attempt to decrypt it will be prosecuted to > the full extent of the law. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#132156) next »