Home >Backend Development >PHP Tutorial >一个PHP算法方面的计算题。

一个PHP算法方面的计算题。

WBOY
WBOYOriginal
2016-06-20 12:34:411437browse

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>';            }        }    }}?>



赞一个啊!!版主真棒。

@傲雪星枫 老大,我又追问了一贴,请你回答一下我啊。

Statement:
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