日期:2014-05-17  浏览次数:20444 次

对象元素名中含变量怎么办?
对象元素名中含变量怎么办?



------解决方案--------------------
$hello->${'name_'.($i+1)}
------解决方案--------------------
$name = 'name_'.($i+1);
$hello->$name;
------解决方案--------------------
探讨

PHP code

<?php
$hello= new stdClass();
$hello->name_1= "du yue bo";
$i=0;
echo $hello->${'name_'.($i+1)};

?>




报错
Notice: Undefined variable: name_1 in D:\PHPnow-1.5.6\htdocs\l……