Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the max value from given multidimensional array using PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 630
    Comment on it

    Hello Reader! If you having an multidiamensnal array and you want to get the max value from a single element key then you see the example below:-

    [0] => stdClass Object
        (
            [id] => TRF1254
            [cust] => CUST9897
            [amount] => 8974
            [balance] => Array
                (
                    [0] => 8987
                )
    
        )
    [1] => stdClass Object
        (
             [id] => TRF1254
            [cust] => CUST9896
            [amount] => 589
            [balance] => Array
                (
                    [0] => 8974
                )
    
        )
    [2] => stdClass Object
        (
            [id] => TRF1259
            [cust] => CUST9659
            [amount] => 1258
            [balance] => Array
                (
                    [0] =>365
                )
    
        )
    

    code for sorting:-

      $numbers = array();
        foreach($array as $obj)
        {
            $numbers[] = $obj->amount;
        }
        $max = max($numbers);
    

 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: