⌂ Home ▲ Previous: PHP features ▼ Next: Constants
In computer science, a literal is a textual representation (notation) of a value as it is written in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, and strings, and usually for Booleans and characters; some also have notations for elements of enumerated types and compound values such as arrays, records, and objects. An anonymous function is a literal for the function type.
In contrast to literals, variables or constants are symbols that can take on one of a class of fixed values, the constant being constrained not to change. Literals are often used to initialize variables.
<?php
$number = 15.5;
$text = "Hello, there!";
print("There is some data.");
print("\nNumber: {$number}\nText: {$text}\n");
View: Example
Execute:
Result:
There is some data.
Number: 15.5
Text: Hello, there!
In the asbove example 15.5 and "Hello, there!" are literals. They are used to initialize (assign a value in the creation process to) two variables. Another literal is "There are some data." used just to be displayed on the output.