I can't seem to sort my array using the standard PHP functions and I don't understand why. Here is;
array (size=5)
0 => string 'Favourite Band' (length=14)
1 => string 'Favourite Pizza' (length=15)
2 => string 'Favourite Side' (length=14)
3 => string 'Favourite Country' (length=17)
4 => string 'Favourite Band' (length=14)
Do I have to use some complex callback on this array or am I overthinking it and missing something obvious?
sort($array), rsort($array), arsort($array) just return a boolean for some reason.
My code;
protected function getUndefinedFields($contacts)
{
$array = [];
foreach ($contacts as $contact) {
foreach ($contact['sub']['customFields'] as $key => $sub_array) {
$array[] = $sub_array['type'];
}
}
}
Edit - Thanks to your comments the penny has dropped. I was doing;
$array = asort($array)
Thinking that would set $array to the sorted array. Not the case. It makes sense to me now that it would return bool but didn't at the time.
sort($array);var_dump($array);should print the sorted array. Sort() - Returns TRUE on success or FALSE on failure.