Page 1 of 1

why is this code returning 31?

Posted: Thu Mar 25, 2004 4:19 pm
by southeastweb
$variable50 = 3+7 * 4;

if anyone can answer this, i would be grateful. the above source is returning 31 on my echo, i know im missing something, cause normal logic says this = 40, thanks in advance! :(

Re: why is this code returning 31?

Posted: Thu Mar 25, 2004 4:25 pm
by aleigh
southeastweb wrote:$variable50 = 3+7 * 4;

if anyone can answer this, i would be grateful. the above source is returning 31 on my echo, i know im missing something, cause normal logic says this = 40, thanks in advance! :(
What you really mean is (3+7)*4. You can learn more at:

http://us4.php.net/manual/en/language.o ... precedence

Posted: Thu Mar 25, 2004 4:40 pm
by John Cartwright
Remember BEDMAS

Brackets
Exponents
Division
Multiplication
Addition
Subtraction

That's the order.

Posted: Thu Mar 25, 2004 5:21 pm
by d3ad1ysp0rk
What??

Pemdas..?

Parenthesis
Exponents
Multiplication
Division
Addition
Subtraction

yup

Posted: Thu Mar 25, 2004 5:32 pm
by southeastweb
i knew it was something simple, never fails. thanks for the help, going to get my precedence straight! Frodo

Posted: Thu Mar 25, 2004 5:50 pm
by tim
I was always taught the phrase:

Please eat my delicious apple soup (Pemdas as punk stated)

it make no sense, apple soup? But I think thats why my class rememberd it, lol.

:wink:

Posted: Thu Mar 25, 2004 6:04 pm
by d3ad1ysp0rk
Please Excuse My Dear Aunt Sally. ;)

Posted: Thu Mar 25, 2004 6:05 pm
by tim
like i said, I think the dumb completly made-up "apple soup" was the true trick behind the memory recall.

lol

Posted: Thu Mar 25, 2004 6:20 pm
by phice
PEMDAS FOR PRESIDENT!

:?

Exponent?

Posted: Thu Mar 25, 2004 6:48 pm
by southeastweb
does exponent refer to the mathmatical term? does anyone know how to use this, or an example, im trying to figure it. thanks guys!


PEDMAS

People Eat Dollar Meals At Subway! :D

my mistake not PEDMAS!

Posted: Thu Mar 25, 2004 6:58 pm
by southeastweb
just to clear myself, i know what an exponent is, just wondering how you use it in php, and example? im heading to php.net thanks for PEMDAS

Posted: Thu Mar 25, 2004 7:52 pm
by d3ad1ysp0rk
function i wrote:

Code: Select all

function raise($num, $exp){
    $value = 1;
    for($i=0;$i<$exp;$i++){
        $value = $value * $num;
    }
    return $value;
}
I'm sure PHP has a function though..

Posted: Thu Mar 25, 2004 8:34 pm
by aleigh
LiLpunkSkateR wrote:function i wrote:

Code: Select all

function raise($num, $exp){
    $value = 1;
    for($i=0;$i<$exp;$i++){
        $value = $value * $num;
    }
    return $value;
}
I'm sure PHP has a function though..
It does; pow()