3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $my_find = array ( 0 => '/abc/'); $my_replace = array( 0 => 'xyz' ); $my_subject = array( 'abcdefg' ); $my_subject = preg_replace( $my_find, $my_replace, $my_subject ); echo "first\n"; print_r($my_find); print_r($my_replace); print_r($my_subject); $my_find = array ( 2 => '/abc/'); $my_replace = array( 2 => 'xyz' ); $my_subject = array( 'abcdefg' ); $my_subject = preg_replace( $my_find, $my_replace, $my_subject ); echo "second\n"; print_r($my_find); print_r($my_replace); print_r($my_subject);
based on Zhf6v
Output for 5.3.21 - 5.6.28, 7.0.2 - 7.2.0
first Array ( [0] => /abc/ ) Array ( [0] => xyz ) Array ( [0] => xyzdefg ) second Array ( [2] => /abc/ ) Array ( [2] => xyz ) Array ( [0] => xyzdefg )
Output for 7.0.0 - 7.0.1
first Array ( [0] => /abc/ ) Array ( [0] => xyz ) Array ( [0] => xyzdefg ) second Array ( [2] => /abc/ ) Array ( [0] => [2] => xyz ) Array ( [0] => defg )