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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
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.0.20, 7.1.0 - 7.1.20, 7.3.32 - 7.3.33
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.5.24 - 5.5.35, 5.6.8 - 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

preferences:
140.72 ms | 403 KiB | 183 Q