What happens if ++ operator is used with string value in PHP?


If you try to use ++ operator with string value then it increments the last character value with 1 and prints the ASCII value.

Following is the PHP code −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
   $values = 'John';
   echo "The string modified value is=",++$values,"<br>";
      $values1="10.5";
   echo "The string incremented value is=",++$values1;
?>
</body>
</html>

Output

The string modified value is=Joho
The string incremented value is=11.5

Updated on: 20-Nov-2020

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements