0

これは私のタイムスタンプの配列です。30秒以内に値を削除し、30秒以内に別の値がない場合にのみ値を保持したいと思います。どんな助けでも大歓迎です!

Array
(
[99999] => Array
    (
        [0] => 1356399000
        [1] => 1356398971
        [2] => 1356399005
        [3] => 1356413406
    )

[99997] => Array
    (
        [0] => 1356399002
        [1] => 1356399007
        [2] => 1356398871
        [3] => 1356398876
    )

[99996] => Array
    (
        [0] => 1356399003
        [1] => 1356399004
        [2] => 1356399008
    )

[99995] => Array
    (
        [0] => 1356399009
    )

)

私の期待する出力:

Array
(
[99999] => Array
    (
        [0] => 1356399000
        [1] => 1356398971
        [2] => 1356413406 
    )

[99997] => Array
    (
        [0] => 1356399002
        [1] => 1356398871
    )

[99996] => Array
    (
        [0] => 1356399003
    )

[99995] => Array
    (
        [0] => 1356399009
    )

)

任意の解決策/アドバイスをいただければ幸いです!ありがとう!

4

1 に答える 1

0

あなたの出力は間違っています..これは私があなたをはっきりと理解している場合1356398971 + 30 = 1356399001よりも素晴らしいので、私はそれがどのように見えるべきか1356399000

$data = array(
  99999 => array(
    0 => 1356399000,
    1 => 1356398971,
    2 => 1356399005,
    3 => 1356413406,
  ),
  99997 => array(
    0 => 1356399002,
    1 => 1356399007,
    2 => 1356398871,
    3 => 1356398876,
  ),
  99996 => array(
    0 => 1356399003,
    1 => 1356399004,
    2 => 1356399008,
  ),
  99995 => array(
    0 => 1356399009,
  ),
);

echo "<pre>";



$data = array_map(function ($values) {
    rsort($values);
    $ci = new CachingIterator(new ArrayIterator($values));
    $values = array();
    foreach ( $ci as $ts ) {
        if ($ci->hasNext()) {
            abs($ci->current() - $ci->getInnerIterator()->current()) > 30 and $values[] = $ts;
        } else {
            $values[] = $ts;
        }
    }
    sort($values);
    return $values;
}, $data);

print_r($data);

出力

Array
(
    [99999] => Array
        (
            [0] => 1356398971
            [1] => 1356413406
        )

    [99997] => Array
        (
            [0] => 1356398871
            [1] => 1356399002
        )

    [99996] => Array
        (
            [0] => 1356399003
        )

    [99995] => Array
        (
            [0] => 1356399009
        )

)
于 2012-12-25T13:43:49.057 に答える