php中数组内对象属性的更新值
我有以下数组:php中数组内对象属性的更新值,php,arrays,object,Php,Arrays,Object,我有以下数组: ( [title] => test [type] => location [status] => 1 [field_locationmap] => stdClass Object ( [und] => stdClass Object ( [0] => stdClass Object
(
[title] => test
[type] => location
[status] => 1
[field_locationmap] => stdClass Object
(
[und] => stdClass Object
(
[0] => stdClass Object
(
[geom] => stdClass Object
(
[lon] => 151.19555790000004
)
)
)
我想问一下,既然“lon”值是数组中的一个对象,如何更改它的值?如果初始变量是数组,则可以执行以下操作:
$zero = 0;
$lon = $array['field_locationmap']->und->$zero->geom->lon;
否则,如果初始变量是stdClass对象:
$zero = 0;
$lon = $object->field_locationmap->und->$zero->geom->lon;
因此,最后,如果要更改此值,只需执行以下操作:
$array['field_locationmap']->und->$zero->geom->lon = 'new value here';