devWhiz Posted July 1, 2011 Share Posted July 1, 2011 so I have info like this.. ID = 40 Cost1 = 20000 Cost2 = 500 ID = 45 Cost1 = 12000 Cost2 = 150 ID = 55 Cost1 = 5000 Cost2 = 300 How can I get this info in an array where I could get the data like this $array[40]['Cost1'] would equal 20000 $array[55]['Cost2'] would equal 300 or if I used print_r($array) it would output Array ( [40] => array ( [iD] => 40 [Cost1] => 20000 [Cost2] => 500 ) [45] => array ( [iD] => 45 [Cost1] => 12000 [Cost2] => 150 ) [55] => array ( [iD] => 55 [Cost1] => 20000 [Cost2] => 500 ) ) or something like that etc etc This is probably easy for most, any help with this is greatly appreciated, thanks Quote Link to comment https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/ Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2011 Share Posted July 1, 2011 Where is the data coming from currently? What is its structure? Quote Link to comment https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/#findComment-1237378 Share on other sites More sharing options...
devWhiz Posted July 1, 2011 Author Share Posted July 1, 2011 well what I was going to do is store all of the data as variables like this $ID45 = 45; $ID45Cost1 = 12000; $ID45Cost2 = 150; $ID40 = 40; $ID40Cost1 = 20000; $ID40Cost2 = 500; $ID55 = 55; $ID55Cost1 = 5000; $ID55Cost2 = 300; I figured it would be easier and faster to put all the information into an array and then call it like $array[iD]['Cost1'], $array[iD]['Cost2'], etc What do you think? any suggestions? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/#findComment-1237386 Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2011 Share Posted July 1, 2011 But where is it coming from to begin with? A form, a database query, or . . . ? Quote Link to comment https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/#findComment-1237387 Share on other sites More sharing options...
devWhiz Posted July 1, 2011 Author Share Posted July 1, 2011 The data is in an XML File but.. the script is going to be doing math, adding the variables and such so I figured it was better to make all of the values as a variable so I would be able to update them, as I wouldnt want php to try and ended the value in the XML file itself, I hope that makes sense Thanks -CLUEL3SS Quote Link to comment https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/#findComment-1237388 Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2011 Share Posted July 1, 2011 Yes, it makes sense. I'm just trying to get enough information so I (or someone else, for that matter) can post a solution that works without a dozen follow-on problems caused by not having sufficient information to begin with. Quote Link to comment https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/#findComment-1237407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.