-
-
Save nb/ac7c4d5f783880917758 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function rawurlencode_deep( $value ) { | |
| if ( is_object( $value ) ) { | |
| foreach( $value as $property => $property_value ) | |
| $value->{$property} = rawurlencode_deep( $property_value ); | |
| return $value; | |
| } else if ( is_array( $value ) ) { | |
| return array_map( 'rawurlencode_deep', $value ); | |
| } else { | |
| return rawurlencode( $value ); | |
| } | |
| } | |
| function map_deep( $f, $value ) { | |
| if ( is_object( $value ) ) { | |
| foreach( $value as $property => $property_value ) | |
| $value->{$property} = map_deep( $f, $property_value ); | |
| return $value; | |
| } else if ( is_array( $value ) ) { | |
| return array_map( $f, $value ); | |
| } else { | |
| return $f( $value ); | |
| } | |
| } | |
| $string = '9386258903475893052389589037 dfuhlksdfkajshfk shkl sdh#$%^&*(P)FGHJKNGVHJBNKMUYIOGHKJLGHKJL"""""asdjkagshdkjsahd'; | |
| $string = (object)array('baba' => 'dyado', 'x' => '123891731231', 'baba' => array( 'x' => 'bababa', 5 => 11), 'super' => 'duper & ? sad"',); | |
| $times = 20000; | |
| var_dump(rawurlencode_deep($string) == map_deep('rawurlencode', $string)); | |
| $start = microtime(true); | |
| for($i=0; $i<$times; $i++) { | |
| $s = map_deep('rawurlencode', $string); | |
| } | |
| echo (microtime(true) - $start)."\n"; | |
| $start = microtime(true); | |
| for($i=0; $i<$times; $i++) { | |
| $s = rawurlencode_deep($string); | |
| } | |
| echo (microtime(true) - $start)."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment