Pre Increment in PHP

Pre increment in php. In this program we can increment the value in previously using operator. Before utilising a variable in an expression, a pre-increment operator is used to increase its value. The value is first increased and then used inside the expression in the Pre-Increment.

<?php
$x = 10;
echo ++$x;
?>

 

Output:

11

PHP Increment Operator

PHP offers a built-in method for incrementing a number or a string by appending ++ to the end of the variable. PHP supports pre- and post-increment and decrement operators in the C manner. Only numbers and strings are affected by the increment/decrement operators. Arrays, objects, booleans, and resources are unaffected by this change. Null values have no effect when decremented, but when incremented, they result in 1.

Echo in PHP

The PHP echo command may be used to output a string, multiple-line strings, escaping characters, variables, arrays, and so on. The statement echo is used to display the output. echo() and echo can be used with or without parentheses. There is no value returned by echo. It produces one or more strings. ‘echo’ can be used to output strings, numbers, variables, values, and expression results.