Code: Select all
($y-($x - 14)) * (0.05) + 0.3Can you have double parenthesis in php?
Moderator: General Moderators
Code: Select all
($y-($x - 14)) * (0.05) + 0.3Code: Select all
<?php
$y = 32;
$x = 15;
echo ($y-($x - 14)) * (0.05) + 0.3
?>
Code: Select all
($y - $x - 14) * 0.05 + 0.3Code: Select all
<html>
<body>
<?php
$y = 32;
$x = 15;
function test()
{
echo (32-(15 - 14)) * (0.05) + 0.3;
}
function test2()
{
echo ($y-($x - 14)) * (0.05) + 0.3;
}
test();
echo '<br />';
test2();
?>
</body>
</html>Edit:PHP Version 5.2.5
System Windows NT MICAH-2OWX70V5B 5.0 build 2195
Build Date Nov 8 2007 23:18:08
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINNT
Loaded Configuration File C:\x\apache\bin\php.ini
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
IPv6 Support enabled
Registered PHP Streams php, file, data, http, ftp, compress.zlib, zip
Registered Stream Socket Transports tcp, udp
Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.*
Code: Select all
echo "The value for x is $x";You refer to $x and $y in a function; unless you declare $x and $y globals, it won't work (the parser will give them a 0 value). Just replace your test2 function with this:groog wrote:But I'm using XAMPP which a lot of php people recommend and use on youtube so I'm guessing it's all up to date.
Ok, so I've found that when this equation is simpley echoed out it's fine. But one thing I didn't mention that this is a custom function. So try this code and see what happens-
test() turns out to be 1.85 and test2() turns out 1. What do you guys get. And the value for $y comes from the previous page and the value for $x comes from a separate php file (using the require function to call it).Code: Select all
<html> <body> <?php $y = 32; $x = 15; function test() { echo (32-(15 - 14)) * (0.05) + 0.3; } function test2() { echo ($y-($x - 14)) * (0.05) + 0.3; } test(); echo '<br />'; test2(); ?> </body> </html>
Ok so here is my php info-PHP Version 5.2.5
System Windows NT MICAH-2OWX70V5B 5.0 build 2195
Build Date Nov 8 2007 23:18:08
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINNT
Loaded Configuration File C:\x\apache\bin\php.ini
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
IPv6 Support enabled
Registered PHP Streams php, file, data, http, ftp, compress.zlib, zip
Registered Stream Socket Transports tcp, udp
Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.*
Code: Select all
function test2()
{
global $x, $y;
echo ($y-($x - 14)) * (0.05) + 0.3;
}Code: Select all
($y - $x - 14) x 0.05 + 0.30Code: Select all
($y - ($x - 14)) x 0.05 + 0.30Code: Select all
$y = 32;
$x = 15;
function test2($x, $y)
{
return ($y-($x - 14)) * (0.05) + 0.3;
}
echo test2($x, $y);