473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

echo the multidimensional array in the table and echo all the information foreach

2 New Member
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <?php
  5.  
  6. $info=array
  7. (
  8.     "Aqilah"=>array
  9.         ("Nama"=> "Aqilah",
  10.          "Umur"=>"20",
  11.          "Jantina"=> "Perempuan"),
  12.  
  13.     "Ali"=>array
  14.         ("Nama"=> "Ali",
  15.          "Umur"=>"30",
  16.          "Jantina"=> "Lelaki"),
  17.  
  18.     "Mary"=>array
  19.         ("Nama"=> "Ali",
  20.          "Umur"=>"21",
  21.          "Jantina"=> "Perempuan"),
  22. );
  23.  
  24. echo"<table border=1 width='250'>";
  25. echo"<tr><th> Nama <th> Umur <th> Jantina </tr>";
  26.  
  27. for($i=0; $i<=2; $i++)
  28. {
  29.     echo"<tr><td> {$info['Aqilah']['$i']} </td>
  30.              <td> {$info["Ali"][$i]} </td>
  31.              <td> {$info["Mary"][$i]} </td>
  32.          </tr>";
  33. }
  34. echo"</table>";
  35.  
  36. foreach ($info as $key=>$value)
  37.  
  38. foreach($value as $iKey=>$iValue)
  39. {
  40.     echo"$iKey:$iValue<br/>";
  41. }
  42. ?>
  43. </body>
  44. </html>
Jul 16 '10 #1
4 1962
chrisoo
2 New Member
Help me pls~
Jul 16 '10 #2
zorgi
431 Recognized Expert Contributor
http://bytes.com/topic/php/answers/880773-grid-view-php
Jul 16 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
maybe someone should try to use the RecursiveArrayIterator() class, that seems applicable
Jul 16 '10 #4
zorgi
431 Recognized Expert Contributor
Actually there is probably no need for it. Because names of the table columns are set at the top:

Expand|Select|Wrap|Line Numbers
  1. echo "<table border='1'>";
  2. echo"<tr><td> Nama </td><td> Umur </td><td> Jantina </td></tr>";
  3.  
To make sure that everything is echoed in its place even if arrays are mixed up like:

Expand|Select|Wrap|Line Numbers
  1. $array=array
  2. (
  3.     "Aqilah"=>array
  4.         ("Nama"=> "Aqilah",
  5.          "Umur"=>"20",
  6.          "Jantina"=> "Perempuan"),
  7.  
  8.     "Ali"=>array
  9.         ("Umur"=>"30",
  10.          "Jantina"=> "Lelaki",
  11.          "Nama"=> "Ali"),
  12.  
  13.     "Mary"=>array
  14.         ("Nama"=> "Ali",
  15.          "Jantina"=> "Perempuan",
  16.          "Umur"=>"21"
  17.          ),
  18. );
  19.  
I think this one foreach loop solution would do just fine here:

Expand|Select|Wrap|Line Numbers
  1. echo "<table border='1'>";
  2. echo"<tr><td> Nama </td><td> Umur </td><td> Jantina </td></tr>";
  3. foreach($array as $row){
  4.     echo "<tr><td>".$row['Nama']."</td><td>".$row['Umur']."</td><td>".$row['Jantina']."</td></tr>";    
  5. }
  6. echo "</table>";
  7.  
Jul 16 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2373
by: Marco | last post by:
I have a couple pages that have tables, whats best use echo to produce the full table with the variables or is it best to just make the table in plain html and use <?php echo ('$va'l); ?> when i...
7
4134
by: Bangalore | last post by:
Hi all, Plz clarify me, on the implementation of two or three dimensional array using overloaded operator. Thanks, in advance Bangalore
4
2968
by: Scot L. Harris | last post by:
Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat 8.0 system. I am writing some php scripts where I want to generate a list of the column names in a particular table that...
2
1448
by: olskar | last post by:
How can I check the number of values in an array and echo them in my PHP script?
4
1997
by: rawky1976 | last post by:
Hi, I have a hyperlink which goes to the page below and passes the PK_ID from a query into 'userid'. From this we query the DB and then echo a table with a form; only the textboxes are already...
3
1351
by: pessi | last post by:
Dear All I have the following code which gives a segmentation fault. I dont think the array size is too large to result in a segmentation fault. Any help please. int xdim = 36; int ydim =...
1
1189
by: unnii | last post by:
Hi All, am new to php and to this forum... Pls help me to get more idea on php. Input File: "EmpDet.txt" whic contains: Id:1,Name:Unni,DOB:31/12/80 Address_1:A1,Address_2=A2...
4
2639
by: student4lifer | last post by:
If I have a multidimentional array that contains many arrays inside as follows: $voters=array(array('name'=>'Joe', 'profession'=>'blumbing', 'state'=>'Ohio'), array('name'=>'Obama',...
13
23443
by: amit2781 | last post by:
How can we get the table schema information in MYSQL 5.1.34? Like we use in ORACLE to get it as: OCIDescribeAny() // //get the describe handle for the table to be described. OCIAttrGet() ...
7
2912
by: w1ck3d64 | last post by:
hi, i have an array of pixel information which i want to display with C/C++. I'm trying to use OpenCV at the moment but I don't have much experience writing pixel by pixel. Can someone show me a...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.