array("param1" => '', "param2" => '', "param3" => "/>  array("param1" => '', "param2" => '', "param3" => ">
Home > Backend Development > PHP Tutorial > 用for给数组赋值解决思路

用for给数组赋值解决思路

WBOY
Release: 2016-06-13 11:55:34
Original
1148 people have browsed it

用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 />
Copy after login


如何用上述方法修改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);
Copy after login
Array<br />(<br />    [id] => 910003<br />    [params] => Array<br />        (<br />            [param1] => param1<br />            [param2] => param2<br />            [param3] => param3<br />        )<br />)<br />
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template