How to create a multi-dimensional array, my data has three columns, id (such as a1 \ a2 .. d1 \ d2), name (name), and age (age, number ). How to use PHP to create this multi-dimensional array?
Include ("IncDB. php ");
$ Result = mysql_query ("SELECT * FROM lists order by id asc", $ link); // all data in this table
$ Row = mysql_fetch_row ($ result );
$ Abcb = array (); // What should I do below? I did not learn it. Thank you.
Reply to discussion (solution)
While ($ row = mysql_fetch_row ($ result )){
$ Abcb [] = $ row;
}
Thank you! If I extract the id = d12 from $ abcb [], what should I do?
Use for loop traversal
For (){
If ($ abcb [$ I] [id] = 'd12 '){
Echo $ abcb [$ I] ['name']. abcb [$ I] ['age'];
}
}
For details, see the output array format.
I can use for, but if FOReach is used, how can I display all the names and ages in $ abcb? Thank you.
while($row=mysql_fetch_assoc($result)){ $abcb[] = $row;}foreach($abcd as $v) { echo "$v[name] $v[age]
";}
Or
while($row=mysql_fetch_row($result)){ $abcb[] = $row;}foreach($abcd as $v) { echo "$v[1] $v[2]
";}
Note: When using the lower mark, pay attention to the order of the field list during query.
Let me ask another question: what does foreach ($ abcd as $ v) mean? Can you explain it?