Jump to content

Need some ideas as to how to go about sorting this array...


Scooby08

Recommended Posts

Here's how the array's are created..

 

<?php
while ($x = readdir($dp)) {
    $order[] = $p['order'];
    $files[] = $x;
}
?>

 

Here's a sample of how they come out..

 

Array
(
    [0] => c
    [1] => f
    [2] => a
    [3] => b
    [4] => d
    [5] => b
    [6] => 
    [7] => e
)

Array
(
    [0] => learn-more
    [1] => apple.php
    [2] => company-info
    [3] => zigzag.php
    [4] => products-services
    [5] => customer-support
    [6] => index.php
    [7] => service-agreements
)

 

How could I sort the files array by using the values of the order array and also make index.php always first to get something like so:

 

Array
(
    [0] => index.php
    [1] => company-info
    [2] => zigzag.php
    [3] => customer-support
    [4] => learn-more
    [5] => products-services
    [6] => service-agreements
    [7] => apple.php
)

 

had to edit since I found the function I was looking for :P

 

<?php 
$order = array('c','f','a','b','d','b','','e');
$files = array('learn-more','apple.php','company-info','zigzag.php','products-services','customer-support','index.php','service-agreements');

array_multisort($order, $files);

print_r($files);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.