3v4l.org

run code in 300+ PHP versions simultaneously
<?php $optimization_prompt = '[not a key] The product title is [title] and the price is [price] and this product link is [link]'; $get_product = ['title' => 'theTitle', 'price' => 45, 'link' => 'https://thelink.com']; $result = preg_replace_callback( '~\[([^][]+)]~', fn($m) => $get_product[$m[1]] ?? $m[0], $optimization_prompt ); echo $result;
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
[not a key] The product title is theTitle and the price is 45 and this product link is https://thelink.com

preferences:
77.74 ms | 407 KiB | 5 Q