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

用for给数组赋值

程序员文章站 2024-02-10 23:03:40
...
$tests=array(id => "910003", params => array("param1" => '', "param2" => '', "param3" => ''));for ($i = 0; $i   

如何用上述方法修改param1,param2,param3值?


回复讨论(解决方案)

$i 应为
$i

$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  
Array(    [id] => 910003    [params] => Array        (            [param1] => 1            [param2] => 2            [param3] => 3        ))

谢谢!,如果这个参数名是没有规律的(如:param_23、paramAbc……),那有如何实现

不是给了你两个方案了吗?

哦,明白了!谢谢!

$tests=array('id' => "910003", 'params' => array(                  "param1" => '',                   "param2" => '',                   "param3" => ''                  ));for ($i = 1; $i  

谢谢!,如果这个参数名是没有规律的(如:param_23、paramAbc……),那有如何实现


如果没有规律,只能换一种办法了
相关标签: 数组 赋值