3v4l.org

run code in 300+ PHP versions simultaneously
<?php $object = new stdClass(); $object->id = 12; $object->datetime = new \DateTime(); $object->foo = 'foo'; $object->bar = 'foo'; $object->a = 'foo'; $object->b = 'foo'; $object->c = 'foo'; $object->d = 'foo'; $object->e = 'foo'; /* @var callable $toArray */ $toArray = null; $toArray = function ($object) use (&$toArray) { $array = []; foreach ($object as $key => $attribute) { if ($attribute instanceof \DateTime) { $array[$key] = $attribute->format('c'); } elseif (is_object($attribute) || is_array($attribute)) { $array[$key] = $toArray($attribute); } else { $array[$key] = $attribute; } } return $array; }; for ($i = 0; $i < 1000; $i++) { $toArray($object); } var_dump($toArray($object));
Output for 5.6.28, 7.0.14 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:01+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.3.32 - 7.3.33, 8.0.13
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T08:14:01+00:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.6
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-05-02T23:55:23+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.5
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-02T13:31:15+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.4
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-09T22:24:45+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.3
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-17T22:48:00+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.2
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-21T09:32:05+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.1
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-23T09:10:35+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 7.0.0
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-26T12:20:13+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.21
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-05-01T19:01:57+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.20
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-09T08:47:39+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.19
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-06T19:35:48+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.18
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-14T07:46:29+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.17
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-19T03:24:21+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.16
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-27T14:02:55+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.15
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-28T14:55:35+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.14
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-01T17:45:11+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.13
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-14T21:41:58+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.12
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-19T10:43:25+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.11
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-22T18:03:41+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.10
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-24T19:41:04+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.9
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-27T00:40:45+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.8
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-29T08:19:17+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.6.7
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-05-24T17:52:45+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.35
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-05-21T22:12:37+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.34
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-10T14:14:22+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.33
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-08T09:31:27+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.32
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-15T18:35:34+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.31
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-20T06:18:49+01:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.30
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-03-31T17:07:20+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.29
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-16T11:40:42+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.28
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-20T13:52:04+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.27
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-21T16:34:13+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.26
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-25T21:54:30+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.25
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-28T04:00:18+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.5.24
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2016-04-30T11:42:03+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.45
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-09-11T04:45:08+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.44
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-09-01T17:22:31+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.43
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-09-01T17:22:28+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.42
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-09-01T17:22:26+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.41
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-25T20:46:50+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.40
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:17+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.36 - 5.4.39
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:18+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.31 - 5.4.35
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:19+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.27 - 5.4.30
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:20+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.22 - 5.4.26
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:21+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.18 - 5.4.21
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:22+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.13 - 5.4.17
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:23+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.8 - 5.4.12
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:24+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.3 - 5.4.7
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:25+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.4.0 - 5.4.2
array(9) { ["id"]=> int(12) ["datetime"]=> string(25) "2015-05-06T10:14:26+02:00" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "foo" ["a"]=> string(3) "foo" ["b"]=> string(3) "foo" ["c"]=> string(3) "foo" ["d"]=> string(3) "foo" ["e"]=> string(3) "foo" }
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/VRQLQ on line 18
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VRQLQ on line 5 Parse error: syntax error, unexpected T_FUNCTION in /in/VRQLQ on line 17
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VRQLQ on line 5 Parse error: parse error, unexpected T_FUNCTION in /in/VRQLQ on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/VRQLQ on line 5 Parse error: parse error in /in/VRQLQ on line 17
Process exited with code 255.

preferences:
239.75 ms | 401 KiB | 355 Q