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 git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
167.44 ms | 405 KiB | 5 Q