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: [EMAIL PROTECTED]

> -----Original Message-----
> From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] 
> Sent: Sunday, 19 January 2003 12:36 PM
> To: [EMAIL PROTECTED]
> 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
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to