rafal Posted December 28, 2014 Share Posted December 28, 2014 Hello Everybody, i have shopping-cart with session_product. i add arrays per button to the session. i want get the shipping1 and shipping2 fields from the array where the field qty great is or equal to 2 >= 2. i did this manualy in my example to get shi1 and shi2 lines 15 and 16. how can i get shipping1 and shipping2 automaticly? thank you very much for your help. here is my code 01.<?php 02.$maxshipping1=0; 03.foreach ($_SESSION['products'] as $pro1) { 04.$maxshipping1 = max($maxshipping1, $pro1['shipping1']); } 05.?> 06.<?php 07.$maxshipping2=0; 08.foreach ($_SESSION['products'] as $pro2) { 09.$maxshipping2 = max($maxshipping2, $pro2['shipping2']); } 10.?> 11.<?php 12.$maxqty=0; 13.foreach ($_SESSION['products'] as $quant) { 14.$maxqty = max($maxqty, $quant['qty']); } 15.$shi1 = $_SESSION["products"][0]["shipping1"]; 16.$shi2 = $_SESSION["products"][0]["shipping2"]; 17.?> the Arrays looks like the following: Array ( [0] => Array ( [product] => Orangensaft 0,3l [code] => 5 [qty] => 3 [price] => 2.99 [shipping1] => 5 [shipping2] => 7 ) [1] => Array ( [product] => Kuchen [code] => 3 [qty] => 1 [price] => 2.95 [shipping1] => 4 [shipping2] => 6 ) [2] => Array ( [product] => Burger 200g [code] => 4 [qty] => 1 [price] => 3.95 [shipping1] => 1 [shipping2] => 3 ) [3] => Array ( [product] => Pizza Pollo [code] => 2 [qty] => 1 [price] => 5.95 [shipping1] => 2 [shipping2] => 4 ) [4] => Array ( [product] => Sake Maki Lachs, 6 St�cke Pommes [code] => 4236134485469 [qty] => 1 [price] => 2 [shipping1] => 1 [shipping2] => 2 ) ) Link to comment https://forums.phpfreaks.com/topic/293457-reading-from-session-array/ Share on other sites More sharing options...
ginerjm Posted December 28, 2014 Share Posted December 28, 2014 Instead of just posting the same code again here and asking a new question on how to use it, may I suggest you do some actual learning? Either stop using arrays or learn how to access them. We helped you with your previous post - not going to do it again. Link to comment https://forums.phpfreaks.com/topic/293457-reading-from-session-array/#findComment-1500974 Share on other sites More sharing options...
Barand Posted December 28, 2014 Share Posted December 28, 2014 To get the values automatically you close your eyes and make a wish. However, as this seldom works, you have to write the code. Why are you looping 3 times through the same array? $maxshipping1=$maxshipping2=$maxqty=0; foreach ($_SESSION['products'] as $prod) { $maxshipping1 = max($maxshipping1, $prod['shipping1']); $maxshipping2 = max($maxshipping2, $prod['shipping2']); $maxqty = max($maxqty, $prod['qty']); if ($prod['qty'] >= 2) { echo $prod['product'] . '<br>'; echo "Ship1: " . $prod["shipping1"] . '<br>'; echo "Ship2: " . $prod["shipping2"] . '<br><br>'; } } Link to comment https://forums.phpfreaks.com/topic/293457-reading-from-session-array/#findComment-1500982 Share on other sites More sharing options...
rafal Posted December 30, 2014 Author Share Posted December 30, 2014 Dear Barand, thank you very much, you are great php expert i sent you email messege here in this forum, please answer. the code working now thank you again Link to comment https://forums.phpfreaks.com/topic/293457-reading-from-session-array/#findComment-1501134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.