Storing and sorting Values in PHP Array

by John H
2 minutes

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:

Related Articles

Working and testing redirects for Apache

Working and testing out redirects for Apache To work on a testing local install of the site make...

John H John H
5 minutes

Adding JS libraries in Laravel

Adding a library in Laravel To add with npm the library needs to be included and compiled with...

John H John H
~1 minute

Javascript InnerHTML Table Issues with AJAX

If you need to use Javascript innerHTML to update an element on the page you may run into issues...

John H John H
~1 minute