Reputation: 8385
I am using in array to try and load a specific dropdown but I am unsure why its not working - I am getting no data from shop_shipping_rule_item_multiple
Array:
array(2) {
[0]=> array(3) {
["shop_shipping_rule_name"]=> string(13) "Overnight UPS"
["shop_shipping_rule_item_multiple"]=> string(4) "4.00"
["shop_shipping_rule_type_multi"]=> string(5) "multi"
}
[1]=> array(3) {
["shop_shipping_rule_name"]=> string(13) "NZ Snail Mail"
["shop_shipping_rule_item_multiple"]=> string(5) "35.00"
["shop_shipping_rule_type_multi"]=> string(5) "multi"
}
}
Code:
<?php foreach($shipping_methods as $method): ?>
<?php if(in_array('shop_shipping_rule_type_multi', $method)): ?>
<option onchange="calShipping()" value="<?php echo $method['shop_shipping_rule_item_multiple'];?>"><?php echo $method['shop_shipping_rule_name'];?> | <?php echo $method['shop_shipping_rule_item_multiple']; ?></option>
<?php else: ?>
<option onchange="calShipping()" value="<?php echo $method['shop_shipping_rule_item_single'];?>"><?php echo $method['shop_shipping_rule_name'];?> | <?php echo $method['shop_shipping_rule_item_single']; ?></option>
<?php endif; ?>
<?php endforeach;?>
Upvotes: 1
Views: 1215
Reputation: 971
Current me if I am wrong, since you are checking for a key in an array you might want to take a look at array_key_exists function Source: https://www.php.net/array_key_exists
i.e.
array_key_exists('shop_shipping_rule_type_multi', $method)
in_array checks if a value exist in a given array
Upvotes: 2