开发者

How do I find max values in a multidimensional array?

开发者 https://www.devze.com 2023-01-17 08:26 出处:网络
I Have an array which looks like this: Array ( [0] => Array ( [0] => Array ( [product] => 2003 [date] => 2010-09-15 13:27:35

I Have an array which looks like this:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [product] => 2003
                    [date] => 2010-09-15 13:27:35
                    [status] => 3
                )

            [1] => Array
                (
                    [product] => 2004
                    [date] => 2010-09-18 13:27:35
                    [status] => 1
                )

            [2] => Array
                (
                    [product] => 2004
                    [date] => 2010-09-18 13:27:35
                    [status] => 6
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [product] => 2003
                    [date] => 2010-09-12 13:27:35
                    [status] => 1
                )

            [1] => Array
                (
                    [product] => 2004
                    [date] => 2010-09-18 13:27:35
                    [status] => 4
                )

            [2] => Array
                (
                    [product] => 2004
                    [date] => 2010-09-18 13:27:35
                    [status] => 1
                )

        )

    [2] => Array
        (
            [0] => 

            [1] => Array
  开发者_运维百科              (
                    [product] => 2004
                    [date] => 2010-09-18 13:27:35
                    [status] => 1
                )

            [2] => Array
                (
                    [product] => 2004
                    [date] => 2010-09-18 13:27:35
                    [status] => 1
                )

        )

I want to "collapse" each second dimension array and obtain the max DATE value and the max status value.So the first index would return 2010-09-18 13:27:35 and '6' etc.

The problem is further complicated by the empty array in the last index. I would like to use this empty array and report it as the MAX date and status.

Thank in advance!


Thanks for looking everybody. I figured it out.

$date=array();
$status=array();
$availability=array();
    foreach($set as $key => $value)
    {
        foreach($value as $value2)
        {

            if(isset($value2[1]))
            {
            $date[$key][]=$value2[1];
            $status[$key][]=$value2[2];

            }
            else
            {
            $date[$key][]='2022-09-18 13:27:35';
            $status[$key][]='0';
            }

        }


                $availability[$key]=array(max($date[$key]),min($status[$key]));

     }  
0

精彩评论

暂无评论...
验证码 换一张
取 消