for出

WBOY
Release: 2016-06-23 14:21:01
Original
940 people have browsed it



function Call_css($str,$cid){
$as= explode(",", $str);
foreach ((array)$as as $Name) {
$IDcss = explode(":", $Name);
if($IDcss[0]==$cid){
echo $IDcss[1]."
";
}else{
echo $cid."---
";
}
}

}

for($i=1;$i Call_css("5:TG1,6:TG2,11:TG3,12:TG44",$i);

}
?>

怎样做到这样
1---
2---
3---
4---
TG1
TG2
7--
8--
9--
10--
TG3
TG44


回复讨论(解决方案)

没看明白数组结构,但估计你中间用 array_unique 处理一下可以达到目的

这样不是更好?

function Call_css($ar,$cid){     echo ($ar[$cid] ? $ar[$cid] : $cid.'--') .'<br>';}$str="5:TG1,6:TG2,11:TG3,12:TG44";$as= explode(",", $str);foreach ((array)$as as $Name) {$IDcss = explode(":", $Name);   $ar[$IDcss[0]]=$IDcss[1];}for($i=1;$i<=12;$i++) {   Call_css($ar,$i);}
Copy after login

function Call_css($str, $cid){  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);}
Copy after login
1---
2---
3---
4---
TG1
TG2
7---
8---
9---
10---
TG3
TG44

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template