php - how to check data from 1 multidimensional array in other multidimensional array -
i have 2 multidimensional array. first 1 $voucher_menu return following array :
this 1 print_r :
array ( [menu_0] => array ( [menu_id] => 521 [qty] => 1 [choice] => array ( [0] => 1 [1] => 6 ) ) [menu_1] => array ( [menu_id] => 525 [qty] => 2 [choice] => array ( [0] => 8 ) ) [menu_2] => array ( [menu_id] => 520 [qty] => 3 [choice] => array ( ) ) ) and second 1 $item_cart return following array :
array ( [menu_0] => array ( [menu_id] => 517 [qty] => 1 [choice] => array ( [0] => 11 [1] => 12 ) ) [menu_1] => array ( [menu_id] => 525 [qty] => 1 [choice] => array ( [0] => 8 ) ) [menu_2] => array ( [menu_id] => 521 [qty] => 2 [choice] => array ( [0] => 2 [1] => 6 ) ) [menu_3] => array ( [menu_id] => 520 [qty] => 3 [choice] => array ( ) ) ) i want trying validate data in $voucher_menu menu_id, value of qty , choice should haved in $item_cart.
this code have done :
for($i=0;$i<count($voucher_menu);$i++){ if(count($voucher_menu["menu_".$i]["choice"]) != 0) { $variant_menu[] = $voucher_menu["menu_" . $i]["choice"]; } } $valid = true; foreach($voucher_menu $row){ $pass = false; foreach($item_cart $value) { if ($row["menu_id"] == $value["menu_id"]) { if (isset($variant_menu)) { if(count($row["choice"]) > 0) { $variant = in_array($row["choice"], $value["choice"]); } } if ($variant == true) { $pass = true; break; } if ($row["qty"] <= $value["qty"]) { $pass = true; break; } } } if(!$pass){ $valid = false; break; } } if($valid == true){ echo "you got discount"; }else{ echo "you dont discount"; } i can validate menu_id , qty of item dont know how validate choice.
i want if in $voucher_menu , if menu_id have choice , array of choice not 0, value choice should same in item_cart
guys can me how check choice? or if have other way validate data $voucher_menu $item_cart please show me.
thank (:
p.s choice string id , return different id if menu_id different if menu_id 521 choice 1, 6 in other menu_id not 1,6
try array_diff or array_intersect
with array_diff can following within loops:
$variant = count(array_diff($row["choice"], $value["choice"])) == 0; you might experiment doing array_diff on whole array of menus , checking if qty different, simplifying code greatly.
Comments
Post a Comment