You would need to write the function by hand.
I would write it in the ecart definition include file so you won't have to add the function to every page manually.
Save a backup of the function since the place where I am having you write it would be rewritten any time you update your cart object.
Then you just need to write the function to perform the logic. PHP is exactly like asp, so the logic is identical and the syntax is only slightly different. The main difference is the function library which is documented well at www.php.net.