3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $row = array(); $row['title'] = 'Mr & Mrs Smith'; $row['surname'] = 'r'; if ( isset($row['title']) && isset($row['surname']) ) { if ( '' !== trim($row['title']) && '' !== trim($row['surname']) ) { if ( -1 !== strpos($row['title'],$row['surname']) ) { $titleParts = explode(' ',$row['title']); if ( count($titleParts) > 1 ) { foreach ( $titleParts as $index => $titlePart ) { if ( $row['surname'] === $titlePart ) { unset($titleParts[$index]); } } $row['title'] = trim(implode(' ',$titleParts)); } } } } var_dump($row['title']);
based on dURdd
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
string(14) "Mr & Mrs Smith"