Phoenix1300 Posted February 7, 2009 Share Posted February 7, 2009 My teacher wants us to write a PHP program that will take 12 US states (any) of my choosing, puts them into an array, and builds a 4x3 table. He wants us to use a multidimensional array to make an "image gallery" of our states in the table, match the name of the states with their picture in their own table cells. Do any of you guys know how to do the multidimensional thing? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/ Share on other sites More sharing options...
Prismatic Posted February 7, 2009 Share Posted February 7, 2009 My teacher wants us to write a PHP program that will take 12 US states (any) of my choosing, puts them into an array, and builds a 4x3 table. He wants us to use a multidimensional array to make an "image gallery" of our states in the table, match the name of the states with their picture in their own table cells. Do any of you guys know how to do the multidimensional thing? Thanks in advance! First, do you know what a multidimensional array is? Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756471 Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 one by one.. OKAY >>write a PHP program that will take 12 US states (any) of my choosing, puts them into an array sry.. i'm live in Indonesia <?php $state=array("Jakarta", "Bali", "East Java", "West Java"); /*try change into your state*/ ?> >>and builds a 4x3 table. <?php $ar=array(); /*just add it*/ $txt.="<table><tr>"; foreach($ar as $state) { $txt.="\n<td>$state</td>"; $i++; if($i%4==0) $txt.="</tr><tr>"; } $txt.="</tr></table>"; $i>12?$txt.="To many state":$txt.="<hr/>"; print $txt; ?> >>He wants us to use a multidimensional array to make an "image gallery" of our states in the table, match the name of the states with their picture in their own table cells. sry.. i don't understand whole.. but you need this kind array <?php $aState=array( array("name"=>"California","img"=>"cal001.png"), array("name"=>"New Jersey","img"=>"jer001.png") ); ?> english isn't my primary languages Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756474 Share on other sites More sharing options...
ngreenwood6 Posted February 7, 2009 Share Posted February 7, 2009 Have you tried googling it? Of course someone on here can do the work for you and you wont learn anything but you will pass the class, or you can make an attempt and most likely fail to get it right(i know i probably would as a noob) and come back and ask someone for help with what you are trying to accomplish so that you actually understand how to do it. Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756475 Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 top: my mistake.. i should explain.. before give the answer. anyway.. do you learn anything from the reply? Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756476 Share on other sites More sharing options...
Phoenix1300 Posted February 7, 2009 Author Share Posted February 7, 2009 I have tried to do it. So far... I've come up with this. I know this isn't what he is asking but this is most likely the extent of my abilities: <html> <head> <title>Assignment 3</title> <link href="assignment.css" rel="stylesheet" type="text/css" /> </head> <body background="images/bg.jpg"> <div><h1>Assignment 3: States II</h1></div> <hr /> <?php $arrayS =array( "VA"=> "Virginia", "NY"=> "New York", "CA"=> "California", "TX"=> "Texas", "IL"=> "Illinois", "WA"=> "Washington", "FL"=> "Florida", "AK"=> "Alaska", "MD"=> "Maryland", "NV"=> "Nevada", "KS"=> "Kansas", "NE"=> "Nebraska", ); echo "<table border='1'>"; echo"<tr><th>State Abbreviations</th><th>State Name</th></tr>"; foreach($arrayS as $Abbr=>$State){ echo "<tr><td>$Abbr </td><td>$State</td></tr> "; } echo "</table>"; ?> </body> </html> What I have so far - a table (two columns) that displays the state abbr on one side and the state name on the other. It's not what the teacher is looking for, but I think it will facilitate me when I try to finish the homework Yes - I have a good idea what multidimensional arrays are, but it's difficult for me to actually make one. :\ Thank you for the help, I'll try to analyze it! Landavia - I don't understand this: What is $ar = array();? What is the foreach loop doing? <?php $ar=array(); /*just add it*/ $txt.="<table><tr>"; foreach($ar as $state) { $txt.="\n<td>$state</td>"; $i++; if($i%4==0) $txt.="</tr><tr>"; } $txt.="</tr></table>"; $i>12?$txt.="To many state":$txt.="<hr/>"; print $txt; ?> Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756480 Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 you answer is for He wants us to use a multidimensional array to make an "image gallery" of our states in the table, match the name of the states with their picture in their own table cells.but where the image? Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756482 Share on other sites More sharing options...
Phoenix1300 Posted February 7, 2009 Author Share Posted February 7, 2009 you answer is for He wants us to use a multidimensional array to make an "image gallery" of our states in the table, match the name of the states with their picture in their own table cells.but where the image? He told me that he wants to have the table and each cell is to have the name of the state and a picture in the cell. Sorta like: ----------|-------| | | | | | | |---------|--------| and goes on Except it has pictures in it, making it look like an "image gallery" Link to comment https://forums.phpfreaks.com/topic/144157-php-multidimensional-array-help/#findComment-756483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.