how to calculate php differential equation [duplicate] - php

This question already has answers here:
Raising to power in PHP
(5 answers)
Closed 7 years ago.
I have a calculation in php like
$outpout = 1.056^(365/10)
But it not calculating in right manner
you can try it like $outpout = (3^3);
Please help me. Thanks in advance.

As of PHP 5.6.0 we have ** operator
If you need 3^3
You can do $x = 3 ** 3 ;
If you are using older version, use
$x = pow(3, 3) ;
In both cases $x will be 27
Source: PHP Documentation

Related

PHP numbers logic [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
What does the percent sign mean in PHP?
(6 answers)
Closed 3 years ago.
I just started to learn PHP deeper for Zend PHP certification and I found this code, which actually works. Can someone explain me the logic behind this?
<?php
$num = 20% - 8;
echo $num; // 4
What you're seeing is the modulus operator, which in essence asks "What is the remainder of 20 divided by -8".
So you might ask, why isn't it negative 4? From the manual,
The result of the modulo operator % has the same sign as the dividend — that is, the result of $a % $b will have the same sign as $a.
See the PHP: Arithmetic Operators for more documentation.
% is not per cent, but modulus, cf. https://en.m.wikipedia.org/wiki/Modular_arithmetic
20 = 2 * 8 + 4, therefore, 20 % 8 = 4

Make decimal value decrease or increase [duplicate]

This question already has answers here:
Round to max thousand, hundred etc in PHP
(5 answers)
Closed 5 years ago.
I have a questions to decrease or increase decimal value in my PHP. For example I have 2573000.00 I want to make it 2500000.00. I have tried to use round() but not give me best answer. How to do that ?
Thank you.
Try this:
$a = 2573000.00;
$b = (int)($a / 100000) * 100000;
echo $b;

Mathematical expression from string [duplicate]

This question already has answers here:
How to make a calculator in PHP?
(3 answers)
Closed 5 years ago.
Can someone please tell if I can in PHP evaluate math expression to number?
For example I have expresssion: (20 + 40%) + 20% I would get 33.6
I tried using EvalMath class from here: https://www.phpclasses.org/package/2695-PHP-Safely-evaluate-mathematical-expressions.html but it doesn't do the trick
Thats just simple math.
If you have an expression $x + $y% - thats the same as $x + (1 + $y/100).
In your case, you could just write
$y = 20;
$x = $y * 1.4 * 1.2;

PHP acting weird on my program [duplicate]

This question already has answers here:
int((0.1+0.7)*10) = 7 in several languages. How to prevent this?
(7 answers)
Closed 8 years ago.
Today i started writing a small PHP code and it left me confusing and so i parked here.
<?php
echo (int) ((0.5 + 0.3) * 10); // Outputs 8 as expected
<?php
echo (int) ((0.1 + 0.7) * 10); // Outputs 7 . How ????
Can someone answer with a detailed explanation ?
It is because floating point representation in computers is not exact for some numbers. As already said in the comments, 0.7 is represented internally as 0.699999 or so.
There are two websites that continuously pop up in these kind of questions:
http://floating-point-gui.de/
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
I prefer the first one, as it is a little lighter on the academics. Read that information and you'll understand.

What does `<<` mean when declaring a variable in PHP? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Strange print behaviour in PHP? [duplicate]
(2 answers)
Closed 10 years ago.
I was looking at this article about facebook's HipHop Virtual Machine (HHVM) when I noticed this line:
<?php
$u_bytes =
$p_bytes = 100 << 20;
I tested it by running echo 100 << 20; and the value was 104857600. What does << 20 do?
Edit
Based on the answers it's a bitwise operator (bit shift [left]). Example:
100 = 000000000000000000001100100
^ `<< 20` moves this bit 20 bits to the left
104857600 = 110010000000000000000000000
This is a bit shift left.
You can learn more on how it works in PHP directly on PHP Manual: http://php.net/manual/en/language.operators.bitwise.php

Categories