array("param1" => '', "param2" => '', "param3" => "/>  array("param1" => '', "param2" => '', "param3" => ">

Home >Backend Development >PHP Tutorial >用for给数组赋值解决思路

用for给数组赋值解决思路

WBOY
WBOYOriginal
2016-06-13 11:55:341168browse

用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 />


如何用上述方法修改param1,param2,param3值?
------解决方案--------------------
$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 />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn