Please Login or Register to continue.


Programming cannot be done without mathematics logic. I want to solve (a+b)2 in the PHP programming language. I am a beginner in PHP. I won't use the mathematics formula  (a+b)2 in the PHP  language. How can convert the mathematics formula (a+b)2 in PHP? It is a famous mathematical formula.


(2.2K Points)
in PHP


1 Answer
(9.2K Points)

PHP programming is based on operators and operands. If you are already learned operators in the C language, you will understand easily. You can use mathematics formula (a+b) in the PHP language. First of all, you need to learn about PHP data types.

Think about the variables in mathematics formula (a+b)2 There is two variable in this formula a and b.

How to open the mathematics formula (a+b)2  


How can write the line mathematics line a2+b2+2ab


if a=2 and b=4



= 4+16+16


You can use this mathematics logic in PHP programming


Asterisk sign (*) is used for multiplication in computer programming languages.

We declare the variables in PHP like this –



Use the above mathematics login –


Let’s create a program for mathematics formula (a+b)2 in PHP language –

echo "(a+b)<sup>2</sup>=a<sup>2</sup>+b<sup>2</sup>+2ab";
echo "=".$result;

You will get the result as output –



You can change variables (a,b) values according to your needs.


Related Questions :-

Your Answer

You can post your answer after login..