Jump to content

Array Trouble


celtech

Recommended Posts

Hello

 

I'm fairly certain that this will be a simple problem to help with, I'm just so rusty with PHP and this is now starting to frustrate me...

 

I have two arrays, one looks like:

    [0] => Array
        (
            [itemID] => 110196213
            [locationID] => 60008524
            [typeID] => 18066
            [quantity] => 37
            [flag] => 4
            [singleton] => 0
        )

And the other like

    [0] => Array
        (
            [18066] => 28
        )

The end result I want to achieve is to loop through the first array, and use only 'typeID' & 'quantity'.I then wish to lookup the 'typeID' & price in the second array.  The typeID is the key I believe (in my example 18066 is the typeID and 28 is the price)So, I look through the first array, take the typeID & quantity.  I look these up in my prices array, and create a running total.Thanks for any help.

 

Please ask questions if you like.

Link to comment
https://forums.phpfreaks.com/topic/121534-array-trouble/
Share on other sites

Wait, is the first array only going to look like that? Or will it get more items etc.

 

If it is just like that they you could just do:

$total = $array2[$array1['typeID']] * $array1['quantity'];

 

If you need to loop then the first array would need to look like this:

 

Array (
	[0] => Array(
				[itemID] => 110196213
			        [locationID] => 60008524
			        [typeID] => 18066
			        [quantity] => 37
			        [flag] => 4
			        [singleton] => 0
			)
	[1] => Array(
				[itemID] => 110196213
			        [locationID] => 60008524
			        [typeID] => 18066
			        [quantity] => 37
			        [flag] => 4
			        [singleton] => 0
			)
)

Link to comment
https://forums.phpfreaks.com/topic/121534-array-trouble/#findComment-626766
Share on other sites

Not working so far. :(

 

This is the logic I'm using to try and total up the prices.  Any help appreciated!

 


$countr = count($asset);
$cost= 0;

for($i=0;$i<=$countr;$i++)
{
  $cost = $cost + ($pricelist[$asset]['typeID'] * $asset['quantity']);
} 

echo ("cost: $cost<br><br>");
print("end");

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/121534-array-trouble/#findComment-626778
Share on other sites

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.