3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = array( 'Bag' => 'Cart', 'Cart' => 'Bag', ); $strings = 'Bag Cart Cart Bag Miscellaneous'; $strings = implode(" ", array_map(fn($v) => $text[$v] ?? $v, explode(" ", $strings))); echo $strings;

preferences:
28.01 ms | 406 KiB | 5 Q