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 = NocWorx_Validate::RX_WHITESPACE; $value = preg_replace("(^{$ws}+|{$ws}+$)", '', $value); } return $value; }; $f2 = function($name, $value) { $ws = NocWorx_Validate::RX_WHITESPACE; $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 Mdd2L
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Class 'NocWorx_Validate' not found in /in/LBCMm:17 Stack trace: #0 /in/LBCMm(50): {closure}('foo', 'hai derr') #1 {main} thrown in /in/LBCMm on line 17
Process exited with code 255.
Output for 5.4.9 - 5.6.28
Fatal error: Class 'NocWorx_Validate' not found in /in/LBCMm on line 17
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/LBCMm on line 40
Process exited with code 255.