3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toBool($var) { if (!is_string($var)) return (bool) $var; switch (strtolower($var)) { case '1': case 'true': case 'on': case 'yes': case 'y': return true; default: return false; } } $strs = ['1', '0', 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n']; foreach ($strs as $str) { echo "toBool($str) : " . (toBool($str) ? 'true' : 'false') . "\n"; echo "filter_var($str) : " . (filter_var($str, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? 'true' : 'false') . "\n"; echo "parse_ini_string($str): " . (parse_ini_string("val = $str")['val'] ? 'true' : 'false') . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
toBool(1) : true filter_var(1) : true parse_ini_string(1): true toBool(0) : false filter_var(0) : false parse_ini_string(0): false toBool(true) : true filter_var(true) : true parse_ini_string(true): true toBool(false) : false filter_var(false) : false parse_ini_string(false): false toBool(on) : true filter_var(on) : true parse_ini_string(on): true toBool(off) : false filter_var(off) : false parse_ini_string(off): false toBool(yes) : true filter_var(yes) : true parse_ini_string(yes): true toBool(no) : false filter_var(no) : false parse_ini_string(no): false toBool(y) : true filter_var(y) : false parse_ini_string(y): true toBool(n) : false filter_var(n) : false parse_ini_string(n): true

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:
27.84 ms | 407 KiB | 5 Q