PHP组指针赋值问题

WBOY
WBOYasal
2016-06-23 13:56:01957semak imbas

$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);?>

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:smarty模板输出字符乱码Artikel seterusnya:php unlink 删除问题