3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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)); } }
based on LBCMm
Output for 7.2.0
Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in /in/hSOIW on line 5 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in /in/hSOIW on line 5 Deprecated: Function create_function() is deprecated in /in/hSOIW on line 24 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50
Output for 7.0.0 - 7.1.10
Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in /in/hSOIW on line 5 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50 Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in /in/hSOIW on line 5 Warning: assert(): assert($f1($name, $value) === $f2($name, $value)) failed in /in/hSOIW on line 50
Output for 5.4.9 - 5.6.28
Warning: assert(): Assertion failed in /in/hSOIW on line 50 Warning: assert(): Assertion failed in /in/hSOIW on line 50 Warning: assert(): Assertion failed in /in/hSOIW on line 50 Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in /in/hSOIW on line 5 Warning: assert(): Assertion failed in /in/hSOIW on line 50 Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in /in/hSOIW on line 5 Warning: assert(): Assertion failed in /in/hSOIW on line 50
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/hSOIW on line 40
Process exited with code 255.