Jump to content

Need help making this array


devWhiz

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/240895-need-help-making-this-array/
Share on other sites

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.