for出
<?php
function Call_css($str,$cid){
$as= explode(",", $str);
foreach ((array)$as as $Name) {
$IDcss = explode(":", $Name);
if($IDcss[0]==$cid){
echo $IDcss[1]."<br>";
}else{
echo $cid."---<br>";
}
}
}
for($i=1;$i<=12;$i++) {
Call_css("5:TG1,6:TG2,11:TG3,12:TG44",$i);
}
?>
怎样做到这样
1---
2---
3---
4---
TG1
TG2
7--
8--
9--
10--
TG3
TG44
[解决办法]
function Call_css($str, $cid){1---
preg_match_all('/(\d+):([^,]+)/', $str, $r);
$r = array_combine($r[1], $r[2]);
echo (isset($r[$cid]) ? $r[$cid] : "$cid---") . '<br>';
}
for($i=1;$i<=12;$i++) {
Call_css("5:TG1,6:TG2,11:TG3,12:TG44",$i);
}