Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.