You are here: Re: [PHP] session_name("CCLTrolley") « PHP « IT news, forums, messages
Re: [PHP] session_name("CCLTrolley")

Posted by Robert Cummings on 12/07/45 11:28

On Mon, 2005-10-03 at 14:11, John Taylor-Johnston wrote:
> Excellent. Thanks. I think I follow what you have done. But to
> clarify, and learn, what are you doing with -= ?
> $trolley[$item] -= $quantity;
> Likewise, i had not followed what you were doing with the lines I
> commented out. They did not seem to work, and I succeeded in doing
> what I wanted without them. I'm a prof, as you can tell, and always
> have a question for an answer ;).
> Thanks for your time and patience,
> John

> > if( isset( $trolley[$item] ) )

"isset" checks that the item with ID $item is in the trolley. No need to
decrease the quantity if it's not there.

> > {
> > $trolley[$item] -= $quantity;

The expression:

$trolley[$item] -= $quantity;

is a short form for the following:

$trolley[$item] = $trolley[$item] - $quantity;

Essentially we decrease the quantity of the given item by $quantity.

> > if( $trolley[$item] < 1 )
> > {

Above we check if we subtracted more items than is physically possible
:)

> > unset( $trolley[$item] );

If there are 0 or less items then there's no point having 0 of the item
in the trolley, so we unset the item from the array, which essentially
removes it completely. To view the difference at each step you can do
the following:

<?php

if( isset( $trolley[$item] ) )
{
echo "Trolley before removing $quantity of $item<br />";
trolleyPrint();

$trolley[$item] -= $quantity;

echo "Trolley after removing $quantity of $item<br />";
trolleyPrint();

if( $trolley[$item] < 1 )
{
unset( $trolley[$item] );

echo "Trolley after cleaning up empty entry for $item<br />";
trolleyPrint();
}
}

?>

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация