Home >Backend Development >PHP Tutorial >PHP组指针赋值问题

PHP组指针赋值问题

WBOY
WBOYOriginal
2016-06-23 13:56:01957browse

$arr=array();$arr['imagePath']="";$arr['Size1']="";$arr['imageaPath']="";$arr['image2Path']="";$arr['Size33']="";$arr['image5Path']="";$arr['Size55']="";$arr['imagebbPath']="";$arr['imageccPath']="";$arr['Size555']="";$arr['imageqqPath']="";$arr['image99Path']="";$arr['imageeePath']="";$arr['imagepPath']="";$arr['Size66']="";$url='/';$arr['imagePath']=$url;$arr['imageaPath']=$url;$arr['image2Path']=$url;$arr['image5Path']=$url;$arr['imagebbPath']=$url;$arr['imageccPath']=$url;$arr['imageqqPath']=$url;$arr['image99Path']=$url;$arr['imageeePath']=$url;$arr['imagepPath']=$url;


回复讨论(解决方案)

楼主的问题是?

$arr=array();$arr['imagePath']="";$arr['Size1']="";$arr['imageaPath']="";$arr['image2Path']="";$arr['Size33']="";$arr['image5Path']="";$arr['Size55']="";$arr['imagebbPath']="";$arr['imageccPath']="";$arr['Size555']="";$arr['imageqqPath']="";$arr['image99Path']="";$arr['imageeePath']="";$arr['imagepPath']="";$arr['Size66']="";$url='/';$arr['imagePath']=$url;$arr['imageaPath']=$url;$arr['image2Path']=$url;$arr['image5Path']=$url;$arr['imagebbPath']=$url;$arr['imageccPath']=$url;$arr['imageqqPath']=$url;$arr['image99Path']=$url;$arr['imageeePath']=$url;$arr['imagepPath']=$url;



这种赋值方法好像有点怪怪的 

楼主的问题是?



这种赋值方法好像有点怪怪的  

$url='/';
$arr['imagePath']=$url;
$arr['imageaPath']=$url;
$arr['image2Path']=$url;
$arr['image5Path']=$url;
$arr['imagebbPath']=$url;
$arr['imageccPath']=$url;
$arr['imageqqPath']=$url;
$arr['image99Path']=$url;
$arr['imageeePath']=$url;
$arr['imagepPath']=$url;

这有什么“怪”呢?
看上去也还算清晰明了

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

这有什么“怪”呢?
看上去也还算清晰明了

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


请教
$k= ?&$v    ??

$k=>&$v
不好意思,按错了键

$k=>&$v
不好意思,按错了键


地址引用,我咋没想到!!!!! 好办法啊!

不引用也是一样的

foreach($ar as $k=>$v) if(substr($k, -4) == 'Path') $ar[$k] = $url;

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

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