Use for to assign values to the array to solve the idea

Source: Internet
Author: User
Assigning a value to an array with a for



$tests =array (id = "910003", params = = Array ("param1" and "=", "param2" + = "," param3 "=") ");

for ($i = 0; $i <= count ($tests ["params"]), $i + +) {

}



How to modify the PARAM1,PARAM2,PARAM3 value using the above method?
------Solution--------------------
$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 <=count ($tests ["params"]), $i + +) {
$tests ["params"] [' param '. $i] = $i;
}
Print_r ($tests);
Array
(
[id] = 910003
[params] = = Array
(
[PARAM1] = 1
[Param2] = 2
[PARAM3] = 3
)
)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.