<?php
$iro = array('おれんじ','あか','きいろ','みどり','きみどり','くろ','しろ','ぴんく','びりじあん');
$kana = array(
"あ行" => "[あ-お]",
"か行" => "[か-こが-ご]",
"さ行" => "[さ-そざ-ぞ]",
"た行" => "[た-とだ-ど]",
"な行" => "[な-の]",
"は行" => "[は-ほば-ぼぱ-ぽ]",
"ま行" => "[ま-も]",
"や行" => "[や-よ]",
"ら行" => "[ら-ろ]",
"わ行" => "[わ-ん]",
"その他" => ".*"
);
$result = array();
foreach ($iro as $value) {
$match = false;
foreach ($kana as $index => $pattern) {
if (preg_match("/^" . $pattern . "/u", $value)) {
$result[$index][] = $value;
$match = true;
break;
}
}
}
print_r($result);
?>
参考サイト
- 教えて!goo
-
読み(あ行~わ行)ごとに分ける方法
- http://oshiete.goo.ne.jp/qa/6669999.html