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

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

WBOY
Release: 2016-06-13 10:17:52
Original
887 people have browsed it

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



------解决方案--------------------
$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……
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template