Skip to content

Instantly share code, notes, and snippets.

@among753
Last active December 19, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save among753/6026608 to your computer and use it in GitHub Desktop.
Save among753/6026608 to your computer and use it in GitHub Desktop.
PHPで配列内の特定の文字が何個あるか検索する方法教えて。。
<?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