I have this foreach loop and i was wondering if there could be a way to sort the array accurding to a value if it's not empty to be at top and the rest goes down. here what I have done so far:
foreach ((array)$accounts as $v=>$k){
if(!empty($k)) {
echo $v;
echo "</br>";
echo $k;
echo "</br>";
} else {
echo $v;
echo "</br>";
}
}
Note: $k
returns either a string or it's just empty not NULL
The ouput is something like:
k1
v1
k2
k3
v3
As you can see k2
has no value. i want it to be at the bottom as it doesn't have a value.
Outputing the array directly with print_r($accounts, TRUE)
:
Array
(
[TwitterSecKey] => Twitter Sec Key
[GoogleSecKey] =>
[InstagramSecKey] => Instagram Sec Key
[FacebookSecKey] =>
)
As you can see Google and Facebook don't have values. so i want them to be at the bottom.