Home  >  Article  >  Backend Development  >  PHP组指针赋值有关问题

PHP组指针赋值有关问题

WBOY
WBOYOriginal
2016-06-13 11:58:271047browse

PHP组指针赋值问题

本帖最后由 pkkgu 于 2014-05-30 09:18:25 编辑
<br />$arr=array();<br />$arr['imagePath']="";<br />$arr['Size1']="";<br />$arr['imageaPath']="";<br />$arr['image2Path']="";<br />$arr['Size33']="";<br />$arr['image5Path']="";<br />$arr['Size55']="";<br />$arr['imagebbPath']="";<br />$arr['imageccPath']="";<br />$arr['Size555']="";<br />$arr['imageqqPath']="";<br />$arr['image99Path']="";<br />$arr['imageeePath']="";<br />$arr['imagepPath']="";<br />$arr['Size66']="";<br /><br /><br />$url='/';<br />$arr['imagePath']=$url;<br />$arr['imageaPath']=$url;<br />$arr['image2Path']=$url;<br />$arr['image5Path']=$url;<br />$arr['imagebbPath']=$url;<br />$arr['imageccPath']=$url;<br />$arr['imageqqPath']=$url;<br />$arr['image99Path']=$url;<br />$arr['imageeePath']=$url;<br />$arr['imagepPath']=$url;<br />

------解决方案--------------------
这有什么“怪”呢?
看上去也还算清晰明了

foreach($ar as $k=?&$v) if(substr($k, -4) == 'Path') $v = $url;

------解决方案--------------------
<br /><?php<br />$arr=array();<br />$arr['imagePath']="";<br />$arr['Size1']="";<br />$arr['imageaPath']="";<br />$arr['image2Path']="";<br />$arr['Size33']="";<br />$arr['image5Path']="";<br />$arr['Size55']="";<br />$arr['imagebbPath']="";<br />$arr['imageccPath']="";<br />$arr['Size555']="";<br />$arr['imageqqPath']="";<br />$arr['image99Path']="";<br />$arr['imageeePath']="";<br />$arr['imagepPath']="";<br />$arr['Size66']="";<br /><br />$url = '/';<br /><br />foreach($arr as $key=>$val){<br />    if(substr($key,0,5)=='image'){<br />        $arr[$key] = $url;<br />    }<br />}<br /><br />print_r($arr);<br /><br />?><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