Ron Piggott schrieb:
I am writing a custom shopping cart that eventually the "cart" will be
uploaded to PayPal for payment.  I need to be able to include the option
that the purchase is a gift certificate.

At present my "add to cart" function goes like this:

# Gift Certificate: 1 is a gift; 2 is personal use

if ( $gift_certificate == "yes" ) {
        $gift = 1;
} else {
        $gift = 2;

$_SESSION['life_coaching_order'][$product][$gift]['quantity'] = $_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;

Now I need to display the shopping cart contents.  I want to do this
through an array as the contents of the shopping cart are in a session
variable.  I start displaying the shopping cart contents by a "FOREACH"

foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
=> $value ) {

What I need help with is that I don't know how to test the value of $gift
in the above array if it is a 1 or 2 (which symbolizes this is a gift

I have something like this in mind:
if ( $_SESSION['life_coaching_order'] == 2 ) {

But I don't know how to access all the components of the array while I am
going through the FOREACH loop.

By using a "1" or "2" I have made gift certificates their own product.  If
you a better method I could use please provide me with this feedback.


The Verse of the Day
Encouragement from God's Word

First at all, I wouldn't use 1 or 2 for defining important informations. use something like
define('ORDER_GIFT', 1);

If you want to check all values of your array you can use several foreach loops like

foreach ($_SESSION['life_coaching_order'] AS $coaching_product => $tmp_array)
 foreach ($tmp_array as $coaching_gift => $tmp_array2)
   switch ($coaching_gift)
     case ORDER_GIFT: break;

     case ORDER_PERSONAL: break;
} }

Personally I would prefer writing a class like

class Order
  private $product;
  private $gift;
  private $quantity;

  const ORDER_GIFT=1;

 function getGift() {
   return $this -> gift;


$_SESSION['life_coaching_order'][] = new Order();

foreach ( $_SESSION['life_coaching_order'] as $order )
 switch ( $order -> getGift() )

     case ORDER_GIFT: break;

     case ORDER_PERSONAL: break;
I hope that will help you,


PHP General Mailing List (
To unsubscribe, visit:

Reply via email to