Example of implementation of PHP two-dimensional array assignment and traversal function

Source: Internet
Author: User
This article mainly introduces PHP simple implementation of two-dimensional array assignment and traversal function, involving the simple assignment of PHP array, traversal, operation, reading and other operations using skills, the need for friends can refer to the next

This paper describes the simple implementation of PHP two-dimensional array assignment and traversal function. Share to everyone for your reference, as follows:

Example 1:


<?php $loptop 1[' lid '] = 1000;  $loptop 1[' pic '] = ' img/1.png ';  $loptop 1[' title '] = ' L1 ';  $loptop 1[' price '] = 5000;  $loptop 1[' isonsale '] = 1;  $loptop 1[' shelftime '] = 1234556;  $loptop 2[' lid '] = 1001;  $loptop 2[' pic '] = ' img/2.png ';  $loptop 2[' title '] = ' L2 ';  $loptop 2[' price '] = 5000;  $loptop 2[' isonsale '] = 1;  $loptop 2[' shelftime '] = 123444456;  $loptop 3[' lid '] = 1002;  $loptop 3[' pic '] = ' img/3.png ';  $loptop 3[' title '] = ' L3 ';  $loptop 3[' price '] = 5000;  $loptop 3[' isonsale '] = 1;  $loptop 3[' shelftime '] = 1243454556;  $loptop 4[' lid '] = 1003;  $loptop 4[' pic '] = ' img/4.png ';  $loptop 4[' title '] = ' L4 ';  $loptop 4[' price '] = 5000;  $loptop 4[' isonsale '] = 1;  $loptop 4[' shelftime '] = 1234364556;  $loptop [0] = $loptop 1;  $loptop [1] = $loptop 2;  $loptop [2] = $loptop 3;  $loptop [3] = $loptop 4;     for ($i =0; $i <count ($loptop), $i + +) {//echo "number: $loptop [$i][lid]";//Error//echo "number:". $loptop [$i] [' lid '];//correct, but not recommended    $tmp = $loptop [$i];    echo "No.: $tmp [lid]<br/>"; echo "Picture: $tmp [Pic]<br/> ";    echo "title: $tmp [title]<br/>";    echo "Price: $tmp [price]<br/>";    echo "is Special: $tmp [isonsale]<br/>"; echo "Shelf time:". Date ("Y-m-d h:i:s", $tmp [' Shelftime ']).  "<br/>"; }?>

Operation Result:


ID: 1000 Image: Img/1.png title: L1 Price: 5000 Special: 1 last time: 1970-01-15 06:55:56 ID: 1001 Image: Img/2. PNG title: L2 Price: 5000 Special: 1 time: 1973-11-29 18:07:36 ID: 1002 Image: Img/3.png title: L3 Price: 5000 Special: 1 Listed: 2009-05-27 20:02:36 ID: 1003 Image: Img/4.png title: L4 Price: 5000 Special: 1 time: 2009-02-11 15:02:36

Example 2:


<?php $stu 1[' sid '] = 1000;  $stu 1[' userName '] = "ABC1";  $stu 1[' passWord '] = "123456";  $stu 1[' email '] = "2109882885@qq.com";  $stu 1[' tel '] = "15700769164";  $stu 1[' Headscu '] = "stu1.png";  $stu 1[' sex '] = "M";  $stu 1[' regtime '] = 1111223435;  $stu 1[' isOnline '] = 1;  $stu 2[' sid '] = 1001;  $stu 2[' userName '] = "ABC2";  $stu 2[' passWord '] = "123456";  $stu 2[' email '] = "2109882886@qq.com";  $stu 2[' tel '] = "15700769165";  $stu 2[' Headscu '] = "stu2.png";  $stu 2[' sex '] = "M";  $stu 2[' regtime '] = 122435344;  $stu 2[' isOnline '] = 1;  $stu 3[' sid '] = 1002;  $stu 3[' userName '] = "ABC3";  $stu 3[' passWord '] = "123456";  $stu 3[' email '] = "2109882887@qq.com";  $stu 3[' tel '] = "15700769166";  $stu 3[' Headscu '] = "stu3.png";  $stu 3[' sex '] = "M";  $stu 3[' regtime '] = 3463464567;  $stu 3[' isOnline '] = 0;  $stu 4[' sid '] = 1003;  $stu 4[' userName '] = "ABC4";  $stu 4[' passWord '] = "123456";  $stu 4[' email '] = "2109882888@qq.com";  $stu 4[' tel '] = "15700769167";  $stu 4[' Headscu '] = "stu4.png";  $stu 4[' sex '] = "F"; $stu4[' regtime '] = 235234534;  $stu 4[' isOnline '] = 1;  $stu = [$stu 1, $stu 2, $stu 3, $stu 4];    for ($i =0; $i <count ($stu); $i + +) {$tmp = $stu [$i];    echo "No.: $tmp [sid]<br/>";    echo "User name: $tmp [username]<br/>";    echo "Password: $tmp [password]<br/>";    echo "Email: $tmp [email]<br/>";    echo "Mobile: $tmp [tel]<br/>";    echo "Avatar: $tmp [headscu]<br/>";    if ($tmp [' sex '] = = "M") {echo "Gender: Male <br/>";    if ($tmp [' sex '] = = "F") {echo "Gender: female <br/>"; } echo "Registration time:". Date (' y-m-d h:i:s ', $tmp [' Regtime ']).    "<br/>";    if ($tmp [' isOnline '] = = 1) {echo "Status: Online <br/>";    if ($tmp [' isOnline '] = = 0) {echo "Status: Not online <br/>"; }}?>

Operation Result:


Item No: 1000 user name: ABC1 password: 123456 e-mail: 2109882885@qq.com Mobile: 15700769164 head: stu1.png Sex: Male Registration date: 2005-03-19 09:10:35 Status: Online ID: 1001 User name: ABC2 password: 123456 e-mail: 2109882886@qq.com Mobile: 15700769165 head: stu2.png Sex: Male Registration date: 1973-11-18 01:49:04 Status: Online ID: 1002 User name: ABC3 password: 123456 e-mail: 2109882887@qq.com Mobile: 15700769166 head: stu3.png Sex: Male Registration date: 1943-08-27 03:01:11 Status: Not Online ID: 1003 user name: abc4 password: 123456 e-mail: 2109882888@qq.com Mobile: 15700769167 head: Stu4.png Sex: Female Registration date: 1977-06-15 14:55:34 Status: Online

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.