Values in PHP

PHP has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

<?php

// Strings, which can be concatenated with the '.' operator.
echo "php" . "lang" . PHP_EOL;

// Integers and floats.
echo "1+1 = " . (1 + 1) . PHP_EOL;
echo "7.0/3.0 = " . (7.0 / 3.0) . PHP_EOL;

// Booleans, with boolean operators as you'd expect.
echo (true && false) ? "true" : "false";
echo PHP_EOL;
echo (true || false) ? "true" : "false";
echo PHP_EOL;
echo (!true) ? "true" : "false";
echo PHP_EOL;

To run the program, save it as values.php and use the PHP interpreter:

$ php values.php
phplang
1+1 = 2
7.0/3.0 = 2.3333333333333
false
true
false

In this PHP example:

  1. We use the echo function to print output, which is similar to fmt.Println in the original example.
  2. String concatenation in PHP uses the . operator instead of +.
  3. PHP uses &&, ||, and ! for logical AND, OR, and NOT operations, respectively, just like in the original example.
  4. We use the ternary operator (?:) to convert boolean results to strings for output, as echo doesn’t automatically convert booleans to strings.
  5. PHP_EOL is used for line breaks, which is equivalent to \n in many other languages.

This example demonstrates basic value types in PHP and how to perform simple operations with them.