当前位置: 代码迷 >> PHP >> 对象元素名中含变量怎么处理
  详细解决方案

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

热度:183   发布时间:2012-04-25 19:32:32.0
对象元素名中含变量怎么办?
对象元素名中含变量怎么办?



------解决方案--------------------
$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……
  相关解决方案