Greystoke Posted April 8, 2011 Share Posted April 8, 2011 Hi, Can anyone help with this please. $products = $cart->get_products(); print_r('$products'); } print_r('$products'); outputs: Array ( [0] => Array ( [id] => 28{7}14 [name] => Pro Install [model] => pro_install [image] => [price] => 25.0000 [quantity] => 1 [weight] => 0.00 [final_price] => 25 [tax_class_id] => 0 [attributes] => Array ( [7] => 14 ) ) [1] => Array ( [id] => 25 [name] => Keyboard [model] => KB [image] => intkeyboardps2.gif [price] => 69.9900 [quantity] => 1 [weight] => 8.00 [final_price] => 69.99 [tax_class_id] => 1 [attributes] => ) ) How do I get it to check the Array for 2 values, 'pro_install' and 'custom_install'. If the values don't exits, I need it to redirect to index.php. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 8, 2011 Share Posted April 8, 2011 if(!isset($products['pro_install']) || !isset($products['custom_install'])) { //redirect code } Quote Link to comment Share on other sites More sharing options...
Greystoke Posted April 8, 2011 Author Share Posted April 8, 2011 Hi, I tried this, but it didn't work. $products = $cart->get_products(); print_r($products); if(!isset($products['pro_install']) || !isset($products['custom_install'])) { echo 'test'; } It still outputs 'test', even when 'pro_install' was in the Array. Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 Please, next time post your print_r with the proper line breaks. Reading a multidimensional array in one line like that is a pain. Here's the deal. $products has two members in your example, [0] and [1]. Each one of those is another array, which have other members. If 'pro_install' and 'custom_install' are supposed to be inside the 'model' key, try this: foreach($products as $product) { if($product['model'] != 'pro_install' && $product['model'] != 'custom_install') { echo 'test'; } } That will loop through each product in $products, echoing 'test' every time it doesn't match both. Quote Link to comment Share on other sites More sharing options...
Greystoke Posted April 8, 2011 Author Share Posted April 8, 2011 Sorry about not posting the print_r correctly. What I want it to do is if 'pro_install' or 'custom_install' are not in the array, then redirect. E.g. If 'pro_install' is there don't redirect. or If 'custom_install' is there don't redirect. or If 'pro_install' and 'custom_install' are there don't redirect. Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 So you're not sure it'll be the 'model' every time? In that case try this: $found = false; foreach($products as $product) { if(in_array('pro_install', $product) || in_array('custom_install', $product)) { $found = true; break; } } if(!$found) { //redirect exit; } else { //do something else } Quote Link to comment Share on other sites More sharing options...
Greystoke Posted April 8, 2011 Author Share Posted April 8, 2011 Thanks for all your help. That's what I was looking for. Quote Link to comment 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.