have two arrays for eg
$arr1 = (1,2,4,3,5);
$arr2 = (10,2,6,19,21);
these are related, ie arr1[x] corresponds to arr2[x]..... they are x and y axis values for a graph.
the problem i have is that my x axis array is not sorted. i am drawing a line graph so i need it sorted.
sort($arr1) works like a charm!
but i want to keep the values linked. is there some type of way to simply achieve this. can i put both arrays into 1 big associative array or something?
i want to end up with
$arr1 = (1,2,3,4,5);
$arr2 = (10,2,19,6,21);........... so only swap values in arr2 that have be swapped in arr1
thanks in advance
-ards
sort two arrays
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
array_combine() would fit the bill nicely. If you're using php4, there are several php4 implementations available (just look through the user comments)
thats a great ftn, thanks feyd
my problem lies now in the fact that some of the x values are duplicates, so the x axis array is more like $arr1 = (60,60,60,61,60,62,62,63,64,65,66) etc
and the array_combine function only takes the last corresponding valeu in the y axis array
i assume because of the properties of an array that you could not have two elements with the same index.
this one has me stumped
my problem lies now in the fact that some of the x values are duplicates, so the x axis array is more like $arr1 = (60,60,60,61,60,62,62,63,64,65,66) etc
and the array_combine function only takes the last corresponding valeu in the y axis array
i assume because of the properties of an array that you could not have two elements with the same index.
this one has me stumped
why not merge your two arrays into one large array with keys => values being xaxis => yaxis
then run some sort of array sorting function that maintains keys, so the values will never be split up.
... hope I made sense there
Edit: Nevermind, that's what the above function does.
Code: Select all
$array = ('xaxis' => 'yaxis', 'xaxis2' => 'yaxis2');... hope I made sense there
Edit: Nevermind, that's what the above function does.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.