3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ 'days' => [ 'day_id' => '2016-11-23,2016-11-24', ], ], [ 'days' => [ 'day_id' => '2016-11-25,', ], ], [ 'days' => [ 'day_id' => '', ], ], [ 'days' => [ 'day_id' => '2016-11-27,2016-11-28', ], ], ]; function reduce_func($carry, $item){ if (isset($item['days']) && !empty($item['days']['day_id'])){ $carry += count(array_unique(array_filter(explode(',', $item['days']['day_id'])))); } return $carry; } $result = array_reduce($arr, "reduce_func"); var_dump($result);
Output for 5.6.0 - 5.6.38, 7.0.0 - 7.0.32, 7.1.0 - 7.1.24, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
int(5)

preferences:
180.7 ms | 403 KiB | 251 Q