noahyamen Posted May 3, 2011 Share Posted May 3, 2011 Ok so I'll try to explain what I'm trying to do the best I can. I want to build an array that allows me to add/remove/modify the variables used at any point in time without having to rebuild or rewrite a ton of new code. For example, below is an example list of variables I'd like to use in the array, followed by the code I would like to be automatically repeated. Example Variables: $materialName1, $materialName2, $materialName3, $materialName4, $materialName5, $materialName6 etc etc etc Example Code to repeat: echo "<tr><td>Material: $materialName1</td><td>Rate: $materialName1Rate</td><td>Weight: $materialName1Weight</td></tr>"; Hopefully that makes sense. As always, very appreciated. Link to comment https://forums.phpfreaks.com/topic/235406-how-would-i-build-this-array-loop/ Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 You can have multidimensional arrays in php very easily. With that said, it's really not clear what you're asking for here or why. Link to comment https://forums.phpfreaks.com/topic/235406-how-would-i-build-this-array-loop/#findComment-1209780 Share on other sites More sharing options...
cyberRobot Posted May 3, 2011 Share Posted May 3, 2011 As gizmola suggested, using a multidimensional array should work. The following tutorial shows a few ways to set up and loop through a multidimensional array: http://www.webcheatsheet.com/PHP/multidimensional_arrays.php Link to comment https://forums.phpfreaks.com/topic/235406-how-would-i-build-this-array-loop/#findComment-1209883 Share on other sites More sharing options...
noahyamen Posted May 4, 2011 Author Share Posted May 4, 2011 Awesome, thats exactly what I was looking for. It will do the trick nicely. Sorry it didnt make much sense. Thanks guys Link to comment https://forums.phpfreaks.com/topic/235406-how-would-i-build-this-array-loop/#findComment-1210181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.