3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $found = null; $route = '/_ticket/_show/xxx'; foreach ( explode( '/', trim( $route, '/' ) ) as $part => $r ) { $uscore = strpos( $r, '_' ); $times = substr_count( $r, '_' ); if ( 1 != $times || 0 != $uscore ) { continue; } $found = $part; break; } if ( null !== $found ) { $parts = explode( '/', trim( $route, '/' ) ); $before = array_slice( $parts, 0, $found, true ); $after = array_slice( $parts, $found + 1, null, true ); $replacePart = ltrim( $parts[ $found ], '_' ); $before[] = $replacePart; $before[] = $replacePart; foreach ( $after as $part ) { $before[] = $part; } var_dump( $before ); }
Output for 5.2.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { [0]=> string(6) "ticket" [1]=> string(6) "ticket" [2]=> string(5) "_show" [3]=> string(3) "xxx" }
Output for 5.0.2 - 5.2.3
array(2) { [0]=> string(6) "ticket" [1]=> string(6) "ticket" }
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.0.1
Warning: Wrong parameter count for array_slice() in /in/VjTIZ on line 22 Warning: Wrong parameter count for array_slice() in /in/VjTIZ on line 23 Warning: Invalid argument supplied for foreach() in /in/VjTIZ on line 29 array(2) { [0]=> string(6) "ticket" [1]=> string(6) "ticket" }
Output for 4.3.11
Warning: Wrong parameter count for array_slice() in /in/VjTIZ on line 22 Warning: Wrong parameter count for array_slice() in /in/VjTIZ on line 23 array(2) { [0]=> string(6) "ticket" [1]=> string(6) "ticket" }