array("param1" => '', "param2" => '', "param3" => "/> array("param1" => '', "param2" => '', "param3" => ">
Heim > Artikel > Backend-Entwicklung > 用for给数组赋值解决思路
用for给数组赋值
<br /><br />$tests=array(id => "910003", params => array("param1" => '', "param2" => '', "param3" => ''));<br /><br />for ($i = 0; $i <= count($tests["params"]); $i++) {<br /> <br />}<br /><br />
$tests = array('id' => "910003", 'params' => array("param1" => '', "param2" => '', "param3" => ''));<br />foreach($tests["params"] as $k=>&$t) $t = $k;<br />print_r($tests);
Array<br />(<br /> [id] => 910003<br /> [params] => Array<br /> (<br /> [param1] => param1<br /> [param2] => param2<br /> [param3] => param3<br /> )<br />)<br />
$tests = array('id' => "910003", 'params' => array("param1" => '', "param2" => '', "param3" => ''));<br />for($i=1; $i<=count($tests["params"]); $i++) {<br /> $tests["params"]['param'.$i] = $i;<br />}<br />print_r($tests);
Array<br />(<br /> [id] => 910003<br /> [params] => Array<br /> (<br /> [param1] => 1<br /> [param2] => 2<br /> [param3] => 3<br /> )<br />)<br />