3v4l.org

run code in 300+ PHP versions simultaneously
<?php $f1 = function($key, $value) { if (preg_match('(_id$)i', $key) !== false) { $value = (is_array($value)) ? array_map($value, 'intval') : intval($value); } elseif (is_array($value)) { foreach ($value as $k => $v) { $value[$k] = $this->_scrubInput($k, $v); } } else { $ws = '\\s'; $value = preg_replace("(^{$ws}+|{$ws}+$)", '', $value); } return $value; }; $f2 = function($name, $value) { $ws = '\\s'; $body = '$v = preg_replace( \'~^' . $ws . '+|' . $ws . '+$~\', \'\', $v ); if( preg_match( \'/_id$/i\', $k ) ) { $v = intval( $v ); } return $v;'; $f = create_function( '$k, &$v', $body ); if( is_array( $value ) ) { // handle arrays of IDs if they are in a xxx_ids var if( preg_match( '/_ids$/', $name ) ) { $value = array_map( 'intval', $value ); } else { array_walk_recursive( $value, $f ); } } else { $value = $f( $name, $value ); } return $value; }; $n = ['foo', 'foo_id']; $v = [ 'hai derr', '1337!', ' hai derr ', ['a_id'=>' 42 tacos', 'b'=>'foo', 'c'=>'blurr'] ]; foreach ($n as $name) { foreach ($v as $value) { assert($f1($name, $value) === $f2($name, $value)); } }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function create_function() in /in/hSOIW:24 Stack trace: #0 /in/hSOIW(50): {closure}('foo', 'hai derr') #1 {main} thrown in /in/hSOIW on line 24
Process exited with code 255.

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:
50.38 ms | 401 KiB | 8 Q