3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getExclusiveORValue() { $args = func_get_args(); $ret = 0; foreach ($args as $arg) { assert('($arg >= 0) && ($arg < PHP_INT_SIZE*8)'); $ret |= 1 << $arg; } return $ret; } function getArrayOfItemsFromExclusiveORValue($bits) { $arr = array(); for ($i=0; $i<PHP_INT_SIZE*8; $i++) { $shift = $bits >> $i; if ($shift & 1) { $arr[] = $i; } if ($shift == 0) { break; } } return $arr; } $bits = getExclusiveORValue(0, 1, 3, 8, 31); echo decbin($bits) . PHP_EOL; // 10000000000000000000000100001011 $arr = getArrayOfItemsFromExclusiveORValue($bits); print_r($arr); /** Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 8 [4] => 31 ) **/
Output for 4.4.0 - 4.4.9, 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.3.32 - 7.3.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
10000000000000000000000100001011 Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 8 [4] => 31 )
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/AQUV7 on line 8 Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/AQUV7 on line 8 Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/AQUV7 on line 8 Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/AQUV7 on line 8 Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/AQUV7 on line 8 10000000000000000000000100001011 Array ( [0] => 0 [1] => 1 [2] => 3 [3] => 8 [4] => 31 )
Output for 4.3.10 - 4.3.11, 5.0.2 - 5.0.4
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 10000000000000000000000100001011 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7 on line 16 Array ( )
Output for 4.3.2 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert(): Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/AQUV7 on line 32 10000000000000000000000100001011PHP_EOL Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7 on line 16 Array ( )
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7(8) : assert code on line 1 Warning: assert() [http://www.php.net/function.assert]: Assertion "($arg >= 0) && ($arg < PHP_INT_SIZE*8)" failed in /in/AQUV7 on line 8 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/AQUV7 on line 32 10000000000000000000000100001011PHP_EOL Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/AQUV7 on line 16 Array ( )

preferences:
328.93 ms | 404 KiB | 460 Q