Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP Condition checking on multidimensional array

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 304
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: