Last active
December 19, 2015 22:19
-
-
Save among753/6026608 to your computer and use it in GitHub Desktop.
PHPで配列内の特定の文字が何個あるか検索する方法教えて。。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array( | |
"あいうえ夢あいう夢おあいうえ", | |
"あい夢夢夢夢夢夢夢夢夢いうえ", | |
"あいうえ夢あいう夢おあいうえ", | |
"あい夢夢夢夢夢夢夢夢夢いうえ", | |
"あい夢えお夢い夢えお夢いうえ", | |
"あ夢夢夢夢夢夢夢夢夢夢夢夢え", | |
"夢いうえおあいうえおあい夢え", | |
"あいう夢夢夢夢夢夢夢あ夢うえ", | |
"あい夢えおあいう夢おあいうえ", | |
"あ夢い夢夢夢夢夢えおあいうえ", | |
"あいうえおあ夢うえおあいうえ", | |
"あいうえお夢いうえおあいうえ", | |
"あいうえ夢あいうえおあいうえ", | |
"あいう夢おあいうえおあいうえ", | |
); | |
$pattern = "/夢/"; | |
$count=0; | |
foreach ($array as $value) { | |
$count += preg_match_all($pattern, $value); | |
} | |
var_dump($count); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment