Page 1 of 1

Do I have to prep $strings prior to math functions?

Posted: Tue Apr 01, 2003 7:43 pm
by 3dron
All values are numbers. But do they become text strings that I need to change before doing simple math on them?

$newoverall_total =
$row_Movie['overall'] + $HTTP_POST_VARS['overall'];

$newoverall_votes = ++$row_Movie['overall_votes'];

$newoverall = $newoverall_total/$newoverall_votes;

Thnaks for any help.

Ron R

Posted: Tue Apr 01, 2003 7:48 pm
by volka
php uses implicit typecasting almost everywhere

Code: Select all

<?php
$a = '1';
$b = '   2  ';
$c = '3dron';
$d = 'nord3';


echo $a+$b, "<br />\n";
echo $a+$c, "<br />\n";
echo $a+$d, "<br />\n";

echo ($b == 2) ? 'true':'false', "<br />\n";
// but
echo ($b === 2) ? 'true':'false';
?>