Пример:
Код: Выделить всё
// let's say I want to add "Has" at beginning (if doesn't exist)
$string_1 = "AnaHasSomeApples"; // we need to add
$string_2 = "HsSomeApples"; // we need to add
$string_3 = "HasApplesAlready"; // already exists at the beginning
Код: Выделить всё
$string = (strpos($string, 'Has') === false ? 'Has' : '') . $string;
Меня больше интересует поиск максимально быстрого (по времени, а не по строкам кода) возможного путь.
Подробнее здесь: https://stackoverflow.com/questions/566 ... esnt-exist
Мобильная версия