lets say we have the following array
$myArray = array(
"foo" => "value1" ,
"bar" => "value2" ,
"baz" => "value3" ,
"qux" => "value4"
);
When looping through this and echoing the value for each one its always going to print foo first, bar second, baz third, and qux fourth. Lets say I want to show the value of qux after foo. What is the best way to do this. I was trying all the different usort,uasort, uksort and wasn’t getting what I wanted.
I saw a lot of good code for moving an index to the top using splice and what not, but I haven’t found the best way to say, how about lets move this index before this other index in the associative array, so that when we loop through it we hit the index we want before the other one.
Not very elegant but it works:
output: