配列の中に特定の文字列があった場合
function sozai_list($ee) { $kuma = get_post_meta($ee,'ic'); $url = get_bloginfo('template_url'); echo "<ul class='tokutei'>"; if (in_array("mugi", $kuma)) { echo "<li class='tokutei'><img src='".$url."/img/menu/ic_komugi.gif' alt='小麦' /></li>"; }else{ echo "<li class='tokutei'><img src='".$url."/img/menu/ic_komugioff.gif' alt='小麦' /></li>"; } if (in_array("egg", $kuma)) { echo "<li class='tokutei'><img src='".$url."/img/menu/ic_tamago.gif' alt='卵' /></li>"; }else{ echo "<li class='tokutei'><img src='".$url."/img/menu/ic_tamagooff.gif' alt='卵' /></li>"; } if (in_array("milk", $kuma)) { echo "<li class='tokutei'><img src='".$url."/img/menu/ic_nyuseihin.gif' alt='乳製品' /></li>"; }else{ echo "<li class='tokutei'><img src='".$url."/img/menu/ic_nyuseihinoff.gif' alt='乳製品' /></li>"; } if (in_array("pi", $kuma)) { echo "<li class='tokutei'><img src='".$url."/img/menu/ic_rakasei.gif' alt='落花生' /></li>"; }else{ echo "<li class='tokutei'><img src='".$url."/img/menu/ic_rakaseioff.gif' alt='落花生' /></li>"; } if (in_array("soba", $kuma)) { echo "<li class='tokuteilast'><img src='".$url."/img/menu/ic_soba.gif' alt='そば' /></li>"; }else{ echo "<li class='tokuteilast'><img src='".$url."/img/menu/ic_sobaoff.gif' alt='そば' /></li>"; } echo "</ul>"; }
in_array("mugi", $kuma)
配列kumaの中にmugiの文字列があるかどうか、あればtrueがかえってくる。