 ×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

# What are Numerical Problems in PHP

See in this article some problems that occur in PHP numerical programs. We will explain what are this and also how to work with it.

Numerical problem is interrelated with all types of programming language. Generally when we are working with different operators like Plus (+), Minus (-), Product (*), Division (/), Modulus (%) sign, the programming model is called numeric types program. Basically we are generating such types of code in our project model. PHP program also support different types of function which supports various numerical solution.

PHP stands for PHP- Hypertext Preprocessor. Through the PHP programming model we can develop different types of numerical prototypical. These types of programming are very helpful at the time of processing project on the base of software development platform. Basically there are two basic types of numbers used in the language: there is 1. integer (int) and 2. float(float). Although there are many languages which distinguish between single and double-precision floating-point numbers but PHP program does all 64-bit floating-point numbers with approximately 14 digits of precision. PHP also maintain the keyword double in addition to float for compatibility.

Fundamentally we know that the Integers which are specified in code in octal (base-8), decimal (base-10), or hexadecimal (base-16) notations format. This following example is the base on all types of number system model.

Listing 1: Showing number system

```<?php \$a = 123; // it is decimal
\$d = -123;
\$g = 0173; // it is  octal, value is 123 in decimal
\$k = -0173; // it is  octal, value is -123 in decimal
\$o = 0x7b; // it is  hexadecimal, 123
\$p = -0x7B; // it is  hexadecimal, -123 ?>
```

Integer precision varies largely by the underlying operating system, but we know 32 bits is common. There are no unsigned integers in PHP, so the maximum value for an integer is typically larger than two billion. Though, unlike other languages that overflow large positive integers into large negative integers but PHP is actually excesses integers to floating-point numbers. Here is an example bellow.

Listing 2: Showing conversion in number system

```<?php \$l = 2147483647;
var_dump(\$l);
\$l = \$l + 1;
var_dump(\$l)
?>
```

The output of this script is int (2147483647) float(2147483648)

### Advantages of PHP Numerical Program:

• Using numerical problem we can easily solve some project as well as some project logic.
• Through this numerical program concept we must develop different types of checking procedure.
• Numerical problem is also standard for developing different types of looping procedure.

### Introduction to operator for PHP Numerical Program:

When we develop the numerical program model then we must have sound knowledge in different types of operator. This all types of operators are working with different types of principal. This principal is taking a major role to develop the program.

### Arithmetic Operators

This is the arithmetic operator designed for Arithmetic Operation.

 Sl.No Operator Description Example Result 1 + Addition(Sum) x=2x+3 5 2 - Subtraction(Minus) x=25-x 3 3 * Multiplication(Product) x=4x*5 20 4 / Division 15/55/2 32.5 5 % Modulus (division remainder) 5%210%810%2 120 6 ++ Increment x=5x++ x=6 7 -- Decrement x=5 , x-- x=4

Table 1: Showing arithmetic operators

### Assignment Operators

This is the Assignment operator designed for Assigning value from one variable to another variable like here.

 Sl.No Operator Example.1 Example.2 1 = x=y x=y 2 += x+=y x=x+y 3 -= x-=y x=x-y 4 *= x*=y x=x*y 5 /= x/=y x=x/y 6 .= x.=y x=x.y 7 %= x%=y x=x%y

Table 2: Showing assignment operators

### Logical Operators

This is the Logical operator designed for comparing data with specific condition.

 Sl.No Operator Description Example 1 == is equal to 9==8 returns false 2 != is not equal 5!=2 returns true 3 is not equal 4 4 > is greater than 3>8 returns false 5 /td> is less than 2 6 >= is greater than or equal to 6>=8 returns false 7 is less than or equal to 7

Table 3: Showing logical operators

### Comparison Operators

This is the Comparison operator designed for comparing two values form one variable to another variable like here.

 Sl.No Operator Description Example 1 && and x=6y=3 (x 1) returns true (Condition is satisfied) 2 || or x=6y=3 (x==5 || y==5) returns false (Condition is not satisfied) 3 ! not x=6 y=4 !(x==y) returns true (Condition is not satisfied)

Table 4: Showing comparison operators

### Increment and Decrement Operators

This is the Increment and Decrement operator designed for looping segment and also other counting problems.

 Sl.no Variable Operation Application 1 ++value Pre-Increment Pre Increment is such types of increment that value is increment before the processing of the data. 2 --value Pre-Decrement Pre decrement is such types of decrement that value is decrement before the processing of the data. 3 value++ Post-Increment Post Increment is such types of increment that value is increment after the processing of the data. 4 value-- Post-Decrement Post decrement is such types of decrement that value is decrement after the processing of the data.

Table 5: Showing increment/decrement operators

### Concept of Combined Operators:

There are some amalgamations operators that we used. There are those who argue that these combination operators provide an advantage because they reduce typing and reduce the final size of the code.

We know that, ‘=’ is an assignment operator, it is used to store data in variable.

\$s = 9 assigns the value 9 to \$s. This assignment can be combined with some other operators like this: \$s += 9

If \$s already had a value of 9, then after this instruction it would be 18, as if the full instruction was: \$a = \$a + 9

Valid combinations include: += -= *= / =

### Precedence and Associativity:

The precedence and associativity is the very standard information in the PHP model programming.

Just we think about this operation and get a numerical conclusion: \$s = 8 - 5 + 1

From this example when minus happens before the plus(+) and the result would be 4. But if we look the plus (+) that happens at first then the result is 2. Since expectedness is indispensable, and the order of precedence was conventional, along with something called associativity. This concept is very vital at the time of programing operation. The order of precedence which is begins a rank for operators. The concept is coming from the way where the highest rank will be evaluated at first. If there are several operators of the same rank, then we will process from left to right. Some operators, such as the comparison operators (a==b) have neither left nor right associativity concept.

The increment and decrement operators (++ and --) are right associative, while the others which are already discussed here are left associative. The order of precedence from the concept of the highest to lowest (with those of equivalent precedence on the identical line) is as follows:

• ++ --
• * / %
• + -
• |
• &&
• | |
• and
• xor
• or

We can override the order of precedence by covering part of an expression in parentheses (backed) like (). The innermost parentheses are processed first, so the following expression is given below:

• (9 - 4) + 1 it will give a result of 6
• 7 - (1 + 1) it will give a result of 5
• 2 + 4 * 3 it will give a result of 18
• 2 + (4 * 3) it will also give 14
• (2 + 4) * 3 it will give a result of 18
• 1 + 3 + 3 * 3 it will give a result of 13
• 1 + ((3 + 3) * 2) it will give a result of 13
• (1 + (3 + 3)) * 2 it will give a result of 14

Parentheses are very useful part when we are creating a complex expression for that reason we choose very easier process for us.

### Example PHP Numerical Program:

Now let us check one example based on PHP numerical program.

Listing 3: Showing PHP numerical program

```
<?php
//Numerical Problem I:Swap Two Numbers without using third variable
\$a=25;
\$b=35;
echo "<b>Value of a before swap....</b>".\$a." ".\$b."</br>";
\$a=\$a+\$b;
\$b=\$a-\$b;
\$a=\$a-\$b;
echo "<b>Value of a after swap....</b>".\$a." ".\$b;

?>
```

This problem states that swap two variable without using third variable.

Listing 4: Showing another PHP numerical program

```<?php
//Numerical Problem II: Checking Variable maximum, minimum
\$a=25;
\$b=35;
\$c=41;
if(\$a>\$b && \$a>\$c)
\$max=\$a;
elseif(\$b>\$c && \$b>\$c)
\$max=\$b;
else
\$max=\$c;

if(\$a<\$b && \$a<\$c)
\$min=\$a;
elseif(\$b<\$c && \$b<\$c)
\$min=\$b;
else
\$min=\$c;
echo "<b>Max number is....</b>".\$max."</br>";
echo "<b>Min number is....</b>".\$min."</br>";

?>
```

This program is used to check if given digit is maximum or minimum.

Listing 5: Showing Factorial of the number

```<?php
//Numerical Problem III:Factorial of the number
\$f=1;
\$n=5;
for(\$i=1;\$i<=\$n;\$i++)
{
\$f=\$f*\$i;
}
echo "<b>Factorial value is....</b>".\$f."</br>";

?>
```

This program checks the factorial of given data. Just like we give 5 that means output will be 1*2*3*4*5=120

Listing 6: Showing Armstrong of the number

```<?php
//Numerical Problem IV: Armstrong of the number
\$n=371;
\$t=\$n;
\$s=0;
while(\$n>0)
{
\$r=\$n%10; // % sign is use for modulus value
\$s=\$s+(\$r*\$r*\$r);
\$n=\$n/10;
}
if(\$t==\$s)
echo "<b>This is Armstrong Number....</b>";
else
echo "<b>This is not Armstrong Number....</b>";
?>
```

This problem is used for checking if the given data is Armstrong or not. If we accept 153 then we can cubing this three digit (1)3+(5)3+(3)3=153 so it is same as given data, so it is called Armstrong Number.

### Conclusion:

From the above circumstance we can assure that numerical problem is the base of our programming model. Through this numerical programming model we can generate different types of logic as well as software development structure. This theory model is very secure for us. We are generally set those types of formation in our programming structure. So, I hope you have got a clear understanding of the concepts and its usage. Try using the concepts in your practical programming. Enjoy reading MrBool. Website: www.techalpine.com Have 16 years of experience as a technical architect and software consultant in enterprise application and product development. Have interest in new technology and innovation area along with technical...

What did you think of this post?
Services

Related Posts

[Close] See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US\$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US\$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US\$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!