Greeting to all!
I've hit a problem whilst sorting multiple PHP arrays... the odd thing is it organised some of the elements correctly, but not the others...
Ok so i've got 3 arrays (Sections '$files', Pages '$files2' and Order '$order').
Now what I wanted it to do is reorganise the $files array based on the values present in $order. However, to do that successfully, it also needs to reorganise the values found in $files2.
Fortunately, i've got it doing this, and it works, but when it does the cubs section, it gets rid of all the values for 'cubs' found in $files2!
Here is the code if anyone has any ideas to the problem:
As always, any thoughts, help etc is appreciated
I've hit a problem whilst sorting multiple PHP arrays... the odd thing is it organised some of the elements correctly, but not the others...
Ok so i've got 3 arrays (Sections '$files', Pages '$files2' and Order '$order').
Code:
$files array
(
[0] => modules
[1] => templates
[2] => tmpuploader
[3] => components
[4] => contact_us
[5] => administrator
[6] => newstmp
[7] => cubs
)
$files2 array
(
[2] => Array
(
[0] => status.php
[1] => upload.php
[2] => upload_progress.php
)
[4] => Array
(
[0] => callback.php
)
[6] => Array
(
[0] => admin.php
[1] => archive.php
[2] => auth.php
[3] => headlines.php
[4] => help.php
[5] => news.php
[6] => sendtofriend.php
[7] => settings.php
)
[7] => Array
(
[0] => badges_and_awards.php
[1] => test.php
)
)
$order array
(
[0] => 2
[1] => 3
[2] => 0
[3] => 1
[4] => 8
[5] => 4
[6] => 5
[7] => 6
)
Now what I wanted it to do is reorganise the $files array based on the values present in $order. However, to do that successfully, it also needs to reorganise the values found in $files2.
Fortunately, i've got it doing this, and it works, but when it does the cubs section, it gets rid of all the values for 'cubs' found in $files2!
Code:
$files array
(
[0] => tmpuploader
[1] => components
[2] => modules
[3] => templates
[4] => administrator
[5] => newstmp
[6] => cubs
[7] => contact_us
)
$files2 array
(
[2] =>
[3] =>
[0] => Array
(
[0] => status.php
[1] => upload.php
[2] => upload_progress.php
)
[1] =>
[7] => Array
(
[0] => callback.php
)
)
$order array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 8
)
Here is the code if anyone has any ideas to the problem:
Code:
print_r($files);
print_r($files2);
print_r($order);
array_multisort($order,$files); //Order the sections based on the order IDs
//Because array_multisort can only handle 2 arrays, do the $files2 array by hand
$files3 = array();
for($i=0;$i<=count($files2);$i++) {
$value = $tmpfiles[$i];
$key = array_search($value,$files);
$files3[$key] = $files2[$i];
}
print_r($files);
print_r($files3);
print_r($order);
As always, any thoughts, help etc is appreciated

)
