0

私は多次元配列を持っています。形式は次のとおりです。

Array
(
    [1] => 2012.09.04;01:00;NZD;ANZ Commodity Price;1;0.5%;;-0.5%;1346720400
    [2] => 2012.09.04;01:30;AUD;Current Account Balance;2;-11.80B;-12.2B;-14.90B;1346722200
    [3] => 2012.09.04;01:30;JPY;Labor Cash Earnings (YoY);2;-1.2%;-0.3%;-0.6%;1346722200
    [4] => 2012.09.04;04:30;AUD;RBA Interest Rate Decision;3;3.5%;3.5%;3.5%;1346733000
    [5] => 2012.09.04;05:45;CHF;Gross Domestic Product (YoY);3;0.5%;1.6%;2.0%;1346737500
)

今、私はこの関数を使用してそれを変換します:

private function array_to_json($array) {    

    $arr_out = array();
    foreach ($array as &$r) {
       $arr_out[] = explode(";", $r);
    }
    unset($r);
    return $arr_out;
}

そして、この結果を得る:

Array
(
    [0] => Array
        (
            [0] => 2012.09.04
            [1] => 01:00
            [2] => NZD
            [3] => ANZ Commodity Price
            [4] => 1
            [5] => 0.5%
            [6] => 
            [7] => -0.5%
            [8] => 1346720400
        )

    [1] => Array
        (
            [0] => 2012.09.04
            [1] => 01:30
            [2] => AUD
            [3] => Current Account Balance
            [4] => 2
            [5] => -11.80B
            [6] => -12.2B
            [7] => -14.90B
            [8] => 1346722200
        )

    [2] => Array
        (
            [0] => 2012.09.04
            [1] => 01:30
            [2] => JPY
            [3] => Labor Cash Earnings (YoY)
            [4] => 2
            [5] => -1.2%
            [6] => -0.3%
            [7] => -0.6%
            [8] => 1346722200
        )

    [3] => Array
        (
            [0] => 2012.09.04
            [1] => 04:30
            [2] => AUD
            [3] => RBA Interest Rate Decision
            [4] => 3
            [5] => 3.5%
            [6] => 3.5%
            [7] => 3.5%
            [8] => 1346733000
        )

    [4] => Array
        (
            [0] => 2012.09.04
            [1] => 05:45
            [2] => CHF
            [3] => Gross Domestic Product (YoY)
            [4] => 3
            [5] => 0.5%
            [6] => 1.6%
            [7] => 2.0%
            [8] => 1346737500
        )

    [5] => Array
        (
            [0] => 2012.09.04
            [1] => 05:45
            [2] => CHF
            [3] => Gross Domestic Product s.a. (QoQ)
            [4] => 2
            [5] => -0.1%
            [6] => 0.2%
            [7] => 0.7%
            [8] => 1346737500
        )
)

[8] はタイムスタンプです。

最初の今後のイベント ([8]>time()) を見つけて、その値を返すにはどうすればよいですか? ありがとう!

4

2 に答える 2

1

[8] のすべての項目を確認し、それぞれについて time() より大きいかどうかを確認する必要があります。その場合は、それらの配列を作成します。最後に、この配列でmin 関数を使用して、最小の数値を取得します。

コード:

$future = array();
foreach($arr_out as $a)
    if ($a[8] > time())
        $future[] = $a[8];

$nearest = min($future); //contains the first upcoming event
于 2012-09-06T08:03:20.403 に答える
0

これを試して:-

$marr = array
(
   array
        (
            '0' => '2012.09.04',
            '1' => '01:30',
            '2' => 'AUD',
            '3' => 'Current Account Balance',
            '4' => 2,
            '5' => '-11.80B',
            '6' => '-12.2B',
            '7' => '-14.90B',
            '8' => 1346919271,
        ),array
        (
            '0' => '2012.09.04',
            '1' => '01:30',
            '2' => 'AUD',
            '3' => 'Current Account Balance',
            '4' => 2,
            '5' => '-11.80B',
            '6' => '-12.2B',
            '7' => '-14.90B',
            '8' => 1346919686,
        )
);

$upComingArray = '';
foreach($marr as $key)
{
    $end =  end($key);
    if ($end > time()){

        $upComingArray[] = $key;
    }
}
echo "<pre>";
print_r($upComingArray);
于 2012-09-06T08:22:53.080 に答える