Storing and sorting Values in PHP Array

I just had a huge ordeal dealing with an array.  I needed to loop through an array – process some tasks – then return a value and store that value along with another value into an array. Once stored into the array I needed to sort based on the key value.

I was finally able to pull it off by declaring the array, then looping my values into the key  and value locations of the array variable.

$list = array();
foreach($filesLocations as $fileLocation) {
$list[$fileName] .= $fileLocation;
}
ksort($list); // SORT THE ARRAY BY THE KEY
foreach ($list as $k => $v) {
 echo “<li><a href=\”$v\”>” .  $k . “</a></li>\n”;
}

What a nightmare!!!

 

Additional resources:

You may also like...