File tree 3 files changed +70
-0
lines changed
solution/0000-0099/0028.Find the Index of the First Occurrence in a String
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,31 @@ impl Solution {
345
345
}
346
346
```
347
347
348
+ ### ** PHP**
349
+
350
+ ``` php
351
+ class Solution {
352
+ /**
353
+ * @param String $haystack
354
+ * @param String $needle
355
+ * @return Integer
356
+ */
357
+ function strStr($haystack, $needle) {
358
+ $strNew = str_replace($needle, "+", $haystack);
359
+ $cnt = substr_count($strNew, "+");
360
+ if ($cnt > 0) {
361
+ for ($i = 0; $i < strlen($strNew); $i++) {
362
+ if ($strNew[$i] == "+") {
363
+ return $i;
364
+ }
365
+ }
366
+ } else {
367
+ return -1;
368
+ }
369
+ }
370
+ }
371
+ ```
372
+
348
373
### ** ...**
349
374
350
375
```
Original file line number Diff line number Diff line change @@ -331,6 +331,31 @@ impl Solution {
331
331
}
332
332
```
333
333
334
+ ### ** PHP**
335
+
336
+ ``` php
337
+ class Solution {
338
+ /**
339
+ * @param String $haystack
340
+ * @param String $needle
341
+ * @return Integer
342
+ */
343
+ function strStr($haystack, $needle) {
344
+ $strNew = str_replace($needle, "+", $haystack);
345
+ $cnt = substr_count($strNew, "+");
346
+ if ($cnt > 0) {
347
+ for ($i = 0; $i < strlen($strNew); $i++) {
348
+ if ($strNew[$i] == "+") {
349
+ return $i;
350
+ }
351
+ }
352
+ } else {
353
+ return -1;
354
+ }
355
+ }
356
+ }
357
+ ```
358
+
334
359
### ** ...**
335
360
336
361
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param String $haystack
4
+ * @param String $needle
5
+ * @return Integer
6
+ */
7
+ function strStr ($haystack , $needle ) {
8
+ $strNew = str_replace ($needle , " +" , $haystack );
9
+ $cnt = substr_count ($strNew , " +" );
10
+ if ($cnt > 0 ) {
11
+ for ($i = 0 ; $i < strlen ($strNew ); $i ++ ) {
12
+ if ($strNew [$i ] == " +" ) {
13
+ return $i ;
14
+ }
15
+ }
16
+ } else {
17
+ return - 1 ;
18
+ }
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments