Php ,在变量中分隔值
我有一个变量$a=271245789Php ,在变量中分隔值,php,Php,我有一个变量$a=271245789 <select name="cat" class="main" multiple="multiple"> <option value="">--Select Category--</option> <? ////////////////display category////////////////
<select name="cat" class="main" multiple="multiple">
<option value="">--Select Category--</option>
<?
////////////////display category//////////////////
$cat_details=mysql_query("select category_id,category from category_tb order by category");
while($cat_data=@mysql_fetch_array($cat_details)){?>
<option value="<?=$cat_data['category_id'];?>" <? if($a==$cat_data['category_id']){?> selected="selected"<? } ?>><?=$cat_data['category'];?></option>
<? } ?>
</select>
--选择类别--
像这样的
if (in_array($value, explode(',', $a)) {
// Found
}
好的,我现在知道了,FIND\u IN\u SET()
做什么了
$index = array_search($value, explode(',', $a));
使用explode()
您可以将此CSV字符串拆分为多个部分,然后在其上应用每个数组
-函数。您可以这样做($key
是$value
在$your\u string
中的位置):
请参阅和的文档。作为您也可以测试的in_array/explode变通方法的替代方法:
function find_in_set($set, $value) {
return strstr(",$set,", ",$value,");
}
不管怎样,我都会把它分开;你的模板已经足够复杂了。(您也应该将mysql_查询移出,并提供一个只返回列表的包装函数。)
function find_in_set($set, $value) {
return strstr(",$set,", ",$value,");
}