PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $string = '[{"test":1,"timeslots":[11,22]},{"test":2,"timeslots":[1231,32],"children":[{"test":12,"timeslots":[2],"children":[{"test":1,"timeslots":[51,522]},{"test":1,"timeslots":[61,622]},{"test":1,"timeslots":[71,722]}]}]}]'; $arr = json_decode($string, true); print_r(array_column($arr, 'timeslots')); $res = array_reduce( array_column($arr, 'timeslots'), fn($ac, $el) => $ac +array_sum($el), 0 ); echo $res;
Show:  
Copy Clear