Page 1 of 1
Stock an array state...
Posted: Thu Jul 21, 2005 9:27 pm
by Sacapuss
Hi !
How do i stock an array state, knowing that if i write array_1=array_0 and then sort array_0, array_1 is sorted too ?
Thanx for your help !
Posted: Thu Jul 21, 2005 9:37 pm
by Burrito
I'm not sure what you mean "stock an array state"
but unless you create an alias to the variable, sorting one of the arrays won't do anything to the other.
Posted: Thu Jul 21, 2005 9:42 pm
by programmermatt
I am not sure how far pointers (or are they called references in PHP?) go in PHP, but I believe this should work:
Code: Select all
$array1 = array('b','c','e','a');
$array2 =& $array1;
array_sort($array2);
// $array2 == $array1
Not sure of the parameters or if array_sort is a valid function, but you get the idea.
Posted: Thu Jul 21, 2005 9:56 pm
by Sacapuss
Thanx for your answers !
I begin with an array : array_0.
I write array_1=array_0, to stock the (order of the) values of array_0 in array_1.
I sort array _0 : array_1 is sorted too, what i don't want.
Look at
http://d.braschi-blondeau.chez.tiscali. ... bj=comptes
click on the first line of the table to see the array original order.
Click on the second line to change the order.
Click on the first line : the order as changed, what i dont want (i want the first line to put the table in the original order.
Posted: Thu Jul 21, 2005 11:33 pm
by harrisonad
in describing you problem, use the store instead of stock to make it clear.
Posted: Sun Jul 31, 2005 4:39 pm
by Sacapuss
Thanx for your answers !
In the end i used array_1=array_0.concat()
see
http://d.braschi-blondeau.chez.tiscali. ... obj=global