用for给数组赋值解决思路
程序员文章站
2022-05-21 14:04:43
...
用for给数组赋值
如何用上述方法修改param1,param2,param3值?
------解决方案--------------------
$tests=array(id => "910003", params => array("param1" => '', "param2" => '', "param3" => ''));
for ($i = 0; $i
}
如何用上述方法修改param1,param2,param3值?
------解决方案--------------------
$tests = array('id' => "910003", 'params' => array("param1" => '', "param2" => '', "param3" => ''));
foreach($tests["params"] as $k=>&$t) $t = $k;
print_r($tests);
Array
(
[id] => 910003
[params] => Array
(
[param1] => param1
[param2] => param2
[param3] => param3
)
)
$tests = array('id' => "910003", 'params' => array("param1" => '', "param2" => '', "param3" => ''));
for($i=1; $i $tests["params"]['param'.$i] = $i;
}
print_r($tests);
Array
(
[id] => 910003
[params] => Array
(
[param1] => 1
[param2] => 2
[param3] => 3
)
)
相关文章
相关视频