I'm trying to replace the matches with numbers by sorting them but couldn't do it. I have a string that has {} in between words. I'd like to change them to 1, 2, 3, etc. without foreach. could be with preg matches all?
$string = 'sample {} test {} string {}';
This string must have seen like this: sample (0) test (1) string (2)
This is my code:
$string_split = explode('{}', $string);
foreach($string as $string_word){
$i ++;
echo $string_word . $i . ' ';
}