我在修改对象数组的值时遇到问题。
array (size=2)
0 =>
object(stdClass)[25]
public 'time1' => string '09:00:00' (length=8)
public 'btm_01' => string '40.00' (length=5)
public 'bto_01' => string '41.00' (length=5)
public 'rs_01' => string '42.00' (length=5)
1 =>
object(stdClass)[26]
public 'time1' => string '10:00:00' (length=8)
public 'btm_01' => string '41.00' (length=5)
public 'bto_01' => string '40.00' (length=5)
public 'rs_01' => string '40.00' (length=5)
我需要一个for循环来删除'。00'中的每个值表示对象数组。移除'。这是很容易的事情,但在我可以删除它之后,我仍然无法用对象数组中的新值替换旧值。
你能帮我,如何修改对象数组的值与PHP?
谢谢!
不,
很简单…我给你举个例子
foreach($data['bottom_max'] as $key => $value)
{
foreach ($value as $name_row => $val_row) {
if (strpos($val_row, '.0')) {
$tmp = substr($val_row, 0, -3);
$data['bottom_max'][$key]->$name_row = $tmp;
}
}
}
希望能回答你的问题。
Easy:
<?php
$object[0]->time1 = '10:00:00';
?>
就像你想象的那样
try this(通过引用访问对象):
foreach($array as & $obj) {
$obj->time1 = $newvalue;
}