3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "I have some fruits like [name], [another_name] and [one_another_name]"; $fruits_array = array("Banana", "Apple", "Orange"); $string = preg_replace_callback( '/\[[^]]+\]/', function ($matches) use (&$fruits_array) { return array_shift($fruits_array); }, $string ); echo $string;

preferences:
58.19 ms | 402 KiB | 5 Q