3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); function get_user_meta($user_id, $key, $ingle) { return 5; } function get_curriculum($id) { return [ 1, 2, 3 ]; } class init { private $time_spent; public function __construct() { $this->time_spent = array(); } public function get_course_unit_time_spent($user_id, $course_id, $unit_id) { if (empty($this->time_spent[$course_id]) || empty($this->time_spent[$course_id][$unit_id])) { $this->time_spent[$course_id][$unit_id] = get_user_meta($user_id, 'time_spent_'.$course_id.'_'.$unit_id, true); if (empty($this->time_spent[$course_id][$unit_id])) { $this->time_spent[$course_id][$unit_id] = 0; } } return $this->time_spent[$course_id][$unit_id]; } public function get_course_time_spent($user_id, $course_id) { if (empty($this->time_spent[$course_id])) { $time_spent = 0; foreach ((array) get_curriculum($course_id) as $unit_id) { if(is_numeric($unit_id)){ $time_spent += $this->get_course_unit_time_spent($user_id, $course_id, $unit_id); } } $this->time_spent[$course_id] = $time_spent; } return $this->time_spent[$course_id]; } } $init = new init; echo $init->get_course_time_spent(1, 234).PHP_EOL; echo $init->get_course_time_spent(2, 2345).PHP_EOL; echo $init->get_course_time_spent(3, 23456).PHP_EOL; print_r($init);
Output for git.master, git.master_jit, rfc.property-hooks
15 15 15 init Object ( [time_spent:init:private] => Array ( [234] => 15 [2345] => 15 [23456] => 15 ) )

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:
29.97 ms | 405 KiB | 5 Q