mrooks1984 Posted August 19, 2012 Share Posted August 19, 2012 hello, i am trying to get my array result to keep adding up the result into the $option_price varible, but i am getting this message: Fatal error: Unsupported operand types on line 209 so put that part of the code on here to see if someone can help. $option_price = '0.00'; foreach ($product_option_prices as $product_option_price) { $option_price .= $option_price + $product_option_price['option_price']; } thanks all Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/ Share on other sites More sharing options...
phpassassin Posted August 19, 2012 Share Posted August 19, 2012 what line on your code is this? $option_price = '0.00'; foreach ($product_option_prices as $product_option_price) { $option_price .= $option_price + $product_option_price['option_price']; } Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370652 Share on other sites More sharing options...
mrooks1984 Posted August 19, 2012 Author Share Posted August 19, 2012 this one is 209: $option_price .= $option_price + $product_option_price['option_price']; thanks. Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370656 Share on other sites More sharing options...
jcbones Posted August 19, 2012 Share Posted August 19, 2012 What does this give you? $option_price = 0; foreach ($product_option_prices as $product_option_price) { $option_price += $product_option_price['option_price']; } You could even type cast to (float). Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370659 Share on other sites More sharing options...
mrooks1984 Posted August 19, 2012 Author Share Posted August 19, 2012 thanks for your reply, still the same. Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370699 Share on other sites More sharing options...
Mahngiel Posted August 19, 2012 Share Posted August 19, 2012 concatenation is for strings. the code jcbones gave you should at least have changed the fatal error. you'll need to supply more information than "still the same" Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370704 Share on other sites More sharing options...
Pikachu2000 Posted August 19, 2012 Share Posted August 19, 2012 What is the structure of $product_option_prices? echo '<pre>'; print_r($product_option_prices); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370705 Share on other sites More sharing options...
mrooks1984 Posted August 19, 2012 Author Share Posted August 19, 2012 hi, Array ( [option_price] => Array ( [1] => 5.00 [2] => 0.00 ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370706 Share on other sites More sharing options...
Pikachu2000 Posted August 19, 2012 Share Posted August 19, 2012 $product_option_prices['option_price'] is another array. That is why you're getting the unsupported operand type error; you're attempting to do 4.125 + array. You can see why that won't work, yes? Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370708 Share on other sites More sharing options...
mrooks1984 Posted August 19, 2012 Author Share Posted August 19, 2012 hi, i this is how i am getting the information into the array //get option prices foreach($_POST['option_price'] as $key => $value){ if($value !=''){ $product_option_prices[] = array("option_price" => $_POST['option_price']); } } and this is the price bit again this is the full print out: Array ( [option_value] => Array ( [1] => Black [2] => Bacon ) ) Array ( [0] => Array ( [option_price] => Array ( [1] => 5.00 [2] => 0.00 ) ) [1] => Array ( [option_price] => Array ( [1] => 5.00 [2] => 0.00 ) ) ) 0 $option_price = 0; if (isset($product_option_values)) { foreach ($product_option_values as $product_option_value); foreach ($product_option_prices as $product_option_price) { //$option_price += $product_option_price['option_price']; } print_r($product_option_value); print_r($product_option_prices); } i thought this is how i call that array $product_option_price['option_price'];? Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370710 Share on other sites More sharing options...
mrooks1984 Posted August 19, 2012 Author Share Posted August 19, 2012 sorted it now, thanks anyway guys Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370735 Share on other sites More sharing options...
mrooks1984 Posted August 19, 2012 Author Share Posted August 19, 2012 hello, hoping someone can help i am stuck on the last bit. if (isset($product_option_values)) { foreach ($store_variations_values as $store_variation_values) { foreach ($product_option_values as $product_option_value) { if($product_option_value == $store_variation_values['title']) { $option_value_price += $store_variation_values['price']; } } } the code above doesent seem to be working i am getting no errors but its not adding it up the if($product_option_value == $store_variation_values['title']) is supposed to compare the option value and get the price for that item from the array, its working it out as 0 and should be 23 including the second value of the loop (1 is 22 and the other is 1) hoping someone could point out were i have gone wrong. Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370738 Share on other sites More sharing options...
darkfreaks Posted August 19, 2012 Share Posted August 19, 2012 have you tried using array_diff instead Quote Link to comment https://forums.phpfreaks.com/topic/267303-array-fatal-error-unsupported-operand-types/#findComment-1370740 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.