3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* ---- 目的 ---- 「同じ日じゃなければ分解して、新しい順にしたい」 というのが目的で、次の$arrを、後述の$newにしたいです。 */ $arr = array( array( 'time' => [1558582388567], // 2019/05/23 'action' => 'get', 'target_id' => 10, 'actor_id' => [87], 'type' => 'a', ), array( 'time' => [1558432437780, 1556542124867], // 2019/05/21, 2019/04/29 'action' => 'get', 'target_id' => 6, 'actor_id' => [9,51], 'type' => 'b', ), array( 'time' => [1556630974513, 1556630915257], // 2019/04/30, 2019/04/30 'action' => 'lose', 'target_id' => 76, 'actor_id' => [87,37], 'type' => 'a', ), ); /* ---- 目的に従って変化した内容 ---- ・$arr[1]には別の日(2019/05/21, 2019/04/29)が混じっているので、分解された。 ・「分解された2019/04/29」よりも、「$arr[2]の2019/04/30」の方が新しいので、並び順が変わった。 というのが$arrから$newへと変化した内容です。 ---- どんな風に使うのか? ---- 「同じ日に、同じアクションを、同じターゲットにした人たち」を1つの配列にまとめたい。 というのが実際の用途になります。 $arrは別の日が混じっている状態なので、同じ日に分解したいというわけです。 */ $new = array( array( // 変化なし 'time' => [1558582388567], // 2019/05/23 'action' => 'get', 'target_id' => 10, 'actor_id' => [87], 'type' => 'a', ), array( // 分解されて新しく作られた配列 'time' => [1558432437780], // 2019/05/21 'action' => 'get', 'target_id' => 6, 'actor_id' => [9], 'type' => 'b', ), array( // 変化なし 'time' => [1556630974513, 1556630915257], // 2019/04/30, 2019/04/30 'action' => 'lose', 'target_id' => 76, 'actor_id' => [87,37], 'type' => 'a', ), array( // 分解された元の配列 'time' => [1556542124867], // 2019/04/29 'action' => 'get', 'target_id' => 6, 'actor_id' => [51], 'type' => 'b', ), );
Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
184.67 ms | 407 KiB | 5 Q