dtxb75622 2018-06-20 07:37
浏览 85

从数组中查找最大月份和类似月份并生成新数组

I have below type array out put and i want max month from the n number of below type array and also month and year has to be available in all n number of array.

Array
(
 [0] => Array
        (
            [0] => Array
                (
                    [month] => 08
                    [year] => 2003
                    [month-year] => 08-2003
                    [strtotime] => 1059676200
                    [percentage] => 1.97
                )

            [1] => Array
                (
                    [month] => 09
                    [year] => 2003
                    [month-year] => 09-2003
                    [strtotime] => 1062354600
                    [percentage] => 5.09
                )

            [2] => Array
                (
                    [month] => 10
                    [year] => 2003
                    [month-year] => 10-2003
                    [strtotime] => 1064946600
                    [percentage] => -0.01
                )

            [3] => Array
                (
                    [month] => 11
                    [year] => 2003
                    [month-year] => 11-2003
                    [strtotime] => 1067625000
                    [percentage] => 0.75
                )

            [4] => Array
                (
                    [month] => 12
                    [year] => 2003
                    [month-year] => 12-2003
                    [strtotime] => 1070217000
                    [percentage] => 5.22
                )

            [5] => Array
                (
                    [month] => 01
                    [year] => 2004
                    [month-year] => 01-2004
                    [strtotime] => 1072895400
                    [percentage] => 1.5
                )

            [6] => Array
                (
                    [month] => 02
                    [year] => 2004
                    [month-year] => 02-2004
                    [strtotime] => 1075573800
                    [percentage] => 1.8
                )

            [7] => Array
                (
                    [month] => 03
                    [year] => 2004
                    [month-year] => 03-2004
                    [strtotime] => 1078079400
                    [percentage] => 0.79
                )

            [8] => Array
                (
                    [month] => 04
                    [year] => 2004
                    [month-year] => 04-2004
                    [strtotime] => 1080757800
                    [percentage] => -0.52
                )

            [9] => Array
                (
                    [month] => 05
                    [year] => 2004
                    [month-year] => 05-2004
                    [strtotime] => 1083349800
                    [percentage] => -2.19
                )

            [10] => Array
                (
                    [month] => 06
                    [year] => 2004
                    [month-year] => 06-2004
                    [strtotime] => 1086028200
                    [percentage] => 1.36
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [month] => 11
                    [year] => 2002
                    [month-year] => 11-2002
                    [strtotime] => 1036089000
                    [percentage] => 0.05
                )

            [1] => Array
                (
                    [month] => 12
                    [year] => 2002
                    [month-year] => 12-2002
                    [strtotime] => 1038681000
                    [percentage] => -0.1
                )

            [2] => Array
                (
                    [month] => 01
                    [year] => 2003
                    [month-year] => 01-2003
                    [strtotime] => 1041359400
                    [percentage] => -0.31
                )

            [3] => Array
                (
                    [month] => 02
                    [year] => 2003
                    [month-year] => 02-2003
                    [strtotime] => 1044037800
                    [percentage] => -0.88
                )

            [4] => Array
                (
                    [month] => 03
                    [year] => 2003
                    [month-year] => 03-2003
                    [strtotime] => 1046457000
                    [percentage] => 1
                )

            [5] => Array
                (
                    [month] => 04
                    [year] => 2003
                    [month-year] => 04-2003
                    [strtotime] => 1049135400
                    [percentage] => 1.63
                )

            [6] => Array
                (
                    [month] => 05
                    [year] => 2003
                    [month-year] => 05-2003
                    [strtotime] => 1051727400
                    [percentage] => 1.35
                )

            [7] => Array
                (
                    [month] => 06
                    [year] => 2003
                    [month-year] => 06-2003
                    [strtotime] => 1054405800
                    [percentage] => 0.05
                )

            [8] => Array
                (
                    [month] => 07
                    [year] => 2003
                    [month-year] => 07-2003
                    [strtotime] => 1056997800
                    [percentage] => 0.5
                )

            [9] => Array
                (
                    [month] => 08
                    [year] => 2003
                    [month-year] => 08-2003
                    [strtotime] => 1059676200
                    [percentage] => 0.65
                )

        )

)

Here is the output so can any one get me similar month and year array with max month.

I have found maximum month from the array by using below foreach loop.

$max = -9999999; 
    $found_item = null; 

    $h = 0;

    foreach($master_array as $k => $v)
    {
        if($v[0]['strtotime'] > $max)
        {
           $max = $v[0]['strtotime'];
           $found_item = $v;
           break;
        }
    }

Here master array is variable that holds above array details. So maximum array is available but i am unable to compare all the month and year from the same variable.

So any one have idea how can i do this.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?