Jump to content

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

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.