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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
3dron
Forum Commoner
Posts: 40
Joined: Sat Feb 01, 2003 10:25 pm

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

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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';
?>
Post Reply