Home >Backend Development >PHP Tutorial >一个PHP算法方面的计算题。
aaa = trim(request("aaa"))
bbb = trim(request("bbb"))
ccc = trim(request("ccc"))
ddd = trim(request("ddd"))
eee = trim(request("eee"))
fff = trim(request("fff"))
ggg = trim(request("ggg"))
hhh = trim(request("hhh"))
。。。。。。。。。。
。。。。。。。。。。
?>
如何用PHP快速计算出本页面到底接收了几个不为空的参数?,并把参数个数及参数值逐一echo出来。
(注意:这些参数中,如果是带有半角逗号或空格时,需要按照多参数来计算。并用split拆分开,也逐一echo出来)
此问题之前已经有一个很好的ASP写法,由于初学PHP,所以不知道怎么改写为PHP的。
网址如下: http://bbs.csdn.net/topics/391906200
<?php$request = $_REQUEST;foreach($request as $k=>$v){ if(trim($v)!=''){ echo $k .'='.$v.PHP_EOL; }}?>
<?php$request = $_REQUEST;foreach($request as $k=>$v){ if(trim($v)!=''){ echo $k .'='.$v.PHP_EOL; }}?>
<?php$request = $_REQUEST; foreach($request as $k=>$v){ if(trim($v)!=''){ $v=str_replace(", ",",",$v); $v=str_replace(" ",",",$v); $arr = explode(',', $v); echo "<hr>key:". $k. "<br>"; foreach($arr as $kk=>$vv){ if(trim($vv)!=''){ echo $k.$kk.'--value:'.$vv.'<br>'; } } }}?>
<?php$request = $_REQUEST; foreach($request as $k=>$v){ if(trim($v)!=''){ $v=str_replace(", ",",",$v); $v=str_replace(" ",",",$v); $arr = explode(',', $v); echo "<hr>key:". $k. "<br>"; foreach($arr as $kk=>$vv){ if(trim($vv)!=''){ echo $k.$kk.'--value:'.$vv.'<br>'; } } }}?>
@傲雪星枫 老大,我又追问了一贴,请你回答一下我啊。