欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

用for给数组赋值解决思路

程序员文章站 2022-05-21 14:04:43
...
用for给数组赋值



$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
)
)
用for给数组赋值解决思路

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频