3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function fillRandom($range, $num = 1, $value = TRUE, $data = array(), $anon = NULL) { if (empty($data)) $data = array_fill($range[0], $range[1]+1, FALSE); if ($anon === NULL) { $anon = function($el) use($value) { return $el !== $value; }; } for ($i=0; $i<$num; $i++) { do { $key = mt_rand($range[0], $range[1]); } while (isSet($data[$key]) && !$anon($data[$key])); $data[$key] = $value; } return $data;}print "<pre>";$input = fillRandom(array(0, 5), 4);ksort($input);print_r($input);$input = fillRandom(array(0, 5), 2, 2, $input, function($el){ return $el === TRUE;});ksort($input);print_r($input);
Output for 5.5.33, 7.1.0
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => [1] => 1 [2] => 2 [3] => [4] => 2 [5] => 1 )
Output for 7.0.14
<pre>Array ( [0] => [1] => [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => [2] => 2 [3] => 1 [4] => 2 [5] => 1 )
Output for 5.3.17, 5.4.3, 5.5.35, 7.0.6
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => [4] => 1 [5] => 1 ) Array ( [0] => 2 [1] => 2 [2] => [3] => [4] => 1 [5] => 1 )
Output for 7.0.5
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => [1] => 1 [2] => 2 [3] => 2 [4] => [5] => 1 )
Output for 5.3.12, 7.0.4
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => [5] => ) Array ( [0] => 2 [1] => 1 [2] => 1 [3] => 2 [4] => [5] => )
Output for 5.3.23, 5.4.36, 7.0.3
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => [1] => 2 [2] => 1 [3] => 2 [4] => [5] => 1 )
Output for 5.3.0, 5.6.28, 7.0.2
<pre>Array ( [0] => [1] => [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => [2] => 1 [3] => 2 [4] => 1 [5] => 2 )
Output for 5.4.41, 7.0.1
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => [5] => ) Array ( [0] => 1 [1] => 2 [2] => 1 [3] => 2 [4] => [5] => )
Output for 5.3.24, 7.0.0
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => 1 [5] => ) Array ( [0] => 1 [1] => 2 [2] => [3] => 1 [4] => 2 [5] => )
Output for 5.6.21
<pre>Array ( [0] => 1 [1] => [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => 2 [1] => [2] => [3] => 2 [4] => 1 [5] => 1 )
Output for 5.4.25, 5.5.26, 5.5.29, 5.6.17, 5.6.20
<pre>Array ( [0] => [1] => 1 [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => 2 [2] => [3] => 1 [4] => 2 [5] => 1 )
Output for 5.6.19
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => 2 [1] => [2] => 1 [3] => 1 [4] => [5] => 2 )
Output for 5.6.18
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => 1 [5] => ) Array ( [0] => 1 [1] => 2 [2] => 1 [3] => [4] => 2 [5] => )
Output for 5.4.4, 5.6.16
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => [1] => 2 [2] => 1 [3] => [4] => 1 [5] => 2 )
Output for 5.4.0, 5.6.15
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => 1 [5] => ) Array ( [0] => 1 [1] => 2 [2] => 2 [3] => [4] => 1 [5] => )
Output for 5.3.14, 5.6.14
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => [5] => 1 ) Array ( [0] => 1 [1] => 1 [2] => [3] => 2 [4] => [5] => 2 )
Output for 5.6.13
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => 2 [1] => [2] => 2 [3] => 1 [4] => 1 [5] => )
Output for 5.4.35, 5.6.12
<pre>Array ( [0] => [1] => [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => [2] => 2 [3] => 2 [4] => 1 [5] => 1 )
Output for 5.3.8, 5.6.11
<pre>Array ( [0] => 1 [1] => [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => 2 [1] => [2] => [3] => 1 [4] => 2 [5] => 1 )
Output for 5.3.11, 5.3.13, 5.5.25, 5.6.10
<pre>Array ( [0] => [1] => [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => [2] => 1 [3] => 2 [4] => 2 [5] => 1 )
Output for 5.3.4, 5.6.9
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => 2 [1] => [2] => 1 [3] => 2 [4] => [5] => 1 )
Output for 5.6.8
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => [5] => 1 ) Array ( [0] => 2 [1] => 1 [2] => [3] => 1 [4] => [5] => 2 )
Output for 5.4.7, 5.4.13, 5.4.39 - 5.4.40, 5.5.34
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => 1 [1] => [2] => 2 [3] => 1 [4] => 2 [5] => )
Output for 5.4.28, 5.5.32
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => [5] => 1 ) Array ( [0] => 2 [1] => 2 [2] => [3] => 1 [4] => [5] => 1 )
Output for 5.4.24, 5.5.31
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => 1 [1] => [2] => 2 [3] => 2 [4] => 1 [5] => )
Output for 5.3.1, 5.4.22, 5.5.30
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => [4] => 1 [5] => 1 ) Array ( [0] => 2 [1] => 1 [2] => [3] => [4] => 2 [5] => 1 )
Output for 5.3.19, 5.5.28
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => [1] => 2 [2] => 2 [3] => 1 [4] => 1 [5] => )
Output for 5.5.27
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => 1 [5] => ) Array ( [0] => 2 [1] => 2 [2] => 1 [3] => [4] => 1 [5] => )
Output for 5.5.24
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => [5] => 1 ) Array ( [0] => 1 [1] => 2 [2] => 2 [3] => [4] => [5] => 1 )
Output for 5.3.10, 5.3.15, 5.4.45
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => [1] => 1 [2] => 2 [3] => 1 [4] => [5] => 2 )
Output for 5.3.2, 5.4.44
<pre>Array ( [0] => [1] => [2] => 1 [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => [2] => 1 [3] => 1 [4] => 2 [5] => 2 )
Output for 5.4.43
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => [5] => 1 ) Array ( [0] => 1 [1] => 2 [2] => [3] => 2 [4] => [5] => 1 )
Output for 5.4.12, 5.4.42
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => [1] => 2 [2] => 2 [3] => [4] => 1 [5] => 1 )
Output for 5.3.16, 5.4.38
<pre>Array ( [0] => [1] => 1 [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => 2 [2] => [3] => 1 [4] => 1 [5] => 2 )
Output for 5.3.22, 5.4.18, 5.4.37
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => [1] => 1 [2] => 2 [3] => [4] => 1 [5] => 2 )
Output for 5.3.20, 5.4.34
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => [5] => ) Array ( [0] => 1 [1] => 2 [2] => 2 [3] => 1 [4] => [5] => )
Output for 5.3.3, 5.4.5, 5.4.20, 5.4.32
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => 1 [1] => [2] => 2 [3] => [4] => 2 [5] => 1 )
Output for 5.4.9, 5.4.21, 5.4.23, 5.4.31
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => [1] => 2 [2] => 1 [3] => 1 [4] => 2 [5] => )
Output for 5.4.30
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => [1] => 2 [2] => 1 [3] => [4] => 2 [5] => 1 )
Output for 5.4.29
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => 1 [5] => ) Array ( [0] => 2 [1] => 1 [2] => [3] => 2 [4] => 1 [5] => )
Output for 5.4.27
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => 1 [1] => [2] => 1 [3] => [4] => 2 [5] => 2 )
Output for 5.4.26
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => 1 [1] => [2] => 2 [3] => [4] => 1 [5] => 2 )
Output for 5.4.1, 5.4.19
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => [4] => 1 [5] => 1 ) Array ( [0] => 1 [1] => 2 [2] => [3] => [4] => 1 [5] => 2 )
Output for 5.4.17
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => [1] => 2 [2] => 1 [3] => 1 [4] => [5] => 2 )
Output for 5.4.16
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => 1 [5] => ) Array ( [0] => 2 [1] => 1 [2] => [3] => 1 [4] => 2 [5] => )
Output for 5.4.15
<pre>Array ( [0] => 1 [1] => [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => 1 [1] => [2] => [3] => 1 [4] => 2 [5] => 2 )
Output for 5.4.14
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => 2 [1] => [2] => 1 [3] => [4] => 2 [5] => 1 )
Output for 5.3.25, 5.4.8, 5.4.11
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => [5] => 1 ) Array ( [0] => 2 [1] => 1 [2] => [3] => 2 [4] => [5] => 1 )
Output for 5.4.10
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => 1 [5] => ) Array ( [0] => 2 [1] => 2 [2] => [3] => 1 [4] => 1 [5] => )
Output for 5.4.6
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => [1] => 1 [2] => 2 [3] => 1 [4] => 2 [5] => )
Output for 5.3.21, 5.4.2
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => [4] => 1 [5] => 1 ) Array ( [0] => 2 [1] => [2] => 1 [3] => [4] => 1 [5] => 2 )
Output for 5.3.7, 5.3.29
<pre>Array ( [0] => [1] => 1 [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => 1 [2] => [3] => 2 [4] => 2 [5] => 1 )
Output for 5.3.28
<pre>Array ( [0] => 1 [1] => 1 [2] => [3] => 1 [4] => 1 [5] => ) Array ( [0] => 1 [1] => 1 [2] => [3] => 2 [4] => 2 [5] => )
Output for 5.3.27
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => [1] => 2 [2] => 2 [3] => 1 [4] => [5] => 1 )
Output for 5.3.26
<pre>Array ( [0] => [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => ) Array ( [0] => [1] => 1 [2] => 2 [3] => 2 [4] => 1 [5] => )
Output for 5.3.18
<pre>Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => [5] => 1 ) Array ( [0] => 1 [1] => [2] => 1 [3] => 2 [4] => [5] => 2 )
Output for 5.3.9
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => 1 [5] => ) Array ( [0] => 2 [1] => 1 [2] => 2 [3] => [4] => 1 [5] => )
Output for 5.3.6
<pre>Array ( [0] => [1] => 1 [2] => [3] => 1 [4] => 1 [5] => 1 ) Array ( [0] => [1] => 1 [2] => [3] => 2 [4] => 1 [5] => 2 )
Output for 5.3.5
<pre>Array ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => [5] => 1 ) Array ( [0] => 1 [1] => 1 [2] => 2 [3] => [4] => [5] => 2 )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/ogPoO on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/ogPoO on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ogPoO on line 3
Process exited with code 255.