Home >Backend Development >PHP Tutorial >对象元素名中含变量怎么处理

对象元素名中含变量怎么处理

WBOY
WBOYOriginal
2016-06-13 10:17:52882browse

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



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

探讨

PHP code

$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……
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