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', ), );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Z1qP
function name:  (null)
number of ops:  3
compiled vars:  !0 = $arr, !1 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, <array>
   49     1        ASSIGN                                                   !1, <array>
   78     2      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.94 ms | 1005 KiB | 13 Q