3v4l.org

run code in 300+ PHP versions simultaneously
<?php $txt = "Text including variables to be replaced, such as {name}, {id}, {something} and {other}"; $vars = array( 'name' => 'name', 'id' => 'userid', 'something' => 'undefinedItem', ); $user = new stdClass(); $user->name = 'James Bond'; $user->userid = '007'; echo str_replace( array_map( function($item) { return '{'. $item .'}'; }, array_keys($vars) ), array_map( function($item) use ($user) { return isset($user->$item) ? $user->$item : 'undefined'; }, $vars ), $txt );

preferences:
44 ms | 402 KiB | 5 Q