[php-src] Issue #11267: wish str_starts_with accepted string|array$needle
| From: | divinity76 | Date: | Thu, 18 May 2023 07:27:35 +0000 |
| Subject: | [php-src] Issue #11267: wish str_starts_with accepted string|array$needle | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244476@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11267
Author: divinity76
### Description
am now in a situation where i have a list of strings i need to check if a string starts with. if
str_starts_with supported string|array $needle, the same way str_replace supports
array|string
$search i could have done
```php
if(str_starts_with($str, $arr)) {
(...)
}
```
but because it doesn't, i instead have to do something like
```php
$startsWith = false;
foreach($arr as $needle){
if(str_starts_with($str, $needle)) {
$startsWith = true;
break;
}
}
if($startsWith) {
(...)
}
```