Re: Math with php

From: Date: Tue, 10 Jun 2003 21:43:53 +0000
Subject: Re: Math with php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-150970@lists.php.net to get a copy of this message
this is untested but should get you going down the right road and this is assuming that you add the value = (6*X + 1*Y) you didn't say that, so I am just guessing. <?php $var = 4; $x = 1; $y = 2; $value = 0; if ( ($var % 2) == 0 ) { $value = ($var * $x); } else { $value = ( ( ($var-1) * $x ) + $y ); } echo $value; ?> Give this a shot, it should give you the results that you are looking for. But remember, this is untested, and just a guess as to the results you are looking for. Jim Lucas ----- Original Message ----- From: "Frank Keessen" <fkeessen@planet.nl> To: <php-general@lists.php.net> Sent: Tuesday, June 10, 2003 2:22 PM Subject: [PHP] Math with php > Hi, > > Hope you can help me: > > How can i do the following in PHP: > > When a variable is for example: > > $a = 7 > > I must do the following 6 * X and 1 * Y, but when $a = 4 it must only do 4 * X. > > So every when the value is odd i must do # * X and # * Y.. > > Some examples or hints are very welcome! Sory that this is maybe a little bit vague... Questions? e-mail! > > Regards, > > Frank >

« previous php.general (#150970) next »