Hi Readers,
We all have used array_values, but we use array_values just to get the values from an array. However, we can do much more than that with the help of it.
One of it's alternative use of array_values is in a situation where we have an array within an array and need to check the condition on the bases of the values present in the second array.
Following is a situation where I am retrieving all those array which contain UserData array in its inner array.
Syntax:-
$finalResult = array_values(array_sort($searchResult, function($value) {
if(!empty($value['UserData'])){
return $value['UserData']['username'];
}
}));
0 Comment(s)