Stock an array state...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Sacapuss
Forum Commoner
Posts: 40
Joined: Mon May 16, 2005 9:46 pm
Location: Earth...

Stock an array state...

Post 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 !
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
programmermatt
Forum Commoner
Posts: 65
Joined: Tue Mar 15, 2005 5:03 pm
Contact:

Post 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.
User avatar
Sacapuss
Forum Commoner
Posts: 40
Joined: Mon May 16, 2005 9:46 pm
Location: Earth...

Post 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.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

in describing you problem, use the store instead of stock to make it clear.
User avatar
Sacapuss
Forum Commoner
Posts: 40
Joined: Mon May 16, 2005 9:46 pm
Location: Earth...

Post 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
Post Reply