echoCurrently, it is considered as
a language construction.
This leads us to conclude that the use of delimiters with parentheses is not necessary, and cannot be used in the function context.
This function returns no value for verification other than its own result.
CAN NOT BE USED TO PRINT ARRAYS and/or OBJECTS.
Is intended to print values of STRINGS and/or NUMBERS and information about RESOURCES.
Under particular conditions, it can be used to print the types: BOOLEAN and NULL.
<?php
void echo ( str $arg1, [, str $arg2, ... str $argN ] );
where,
$arg1 = ELEMENT 1 to be printed
$arg2 = ELEMENT 2 to be printed
. . . . . . . . .
$argN = ELEMENT N to be printed
/* - - - - - - - - - - - - - - - - - - -
Before PHP 5.4.0, if
short_open_tag is enabled,
it could be used:
- - - - - - - - - - - - - - - - - - - */
<?= . . .
which is identical to:
<? echo . . .
/* - - - - - - - - - - - - - - - - - - -
Since PHP 5.4.0
is always available:
- - - - - - - - - - - - - - - - - - - */
<?= . . .
?>
$arg1
The element to be printed.
$arg2, ... $argN
Additional elements to be printed.
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
STRINGS: INTERNAL
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
echo $_SERVER['REMOTE_ADDR'];
// GETS THE REMOTE ADDRES (IP)
echo '<br><br>' . $_SERVER['HTTP_USER_AGENT'];
// GETS THE USER AGENT (BROWSER)
echo '<br><br>' . $_SERVER['HTTP_ACCEPT_LANGUAGE'];
// GETS THE ACEPTED LANGUAGE
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?>
RESULT
- - - - - - - - - - - - - - - - - - - - - - - - - - -
::1
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
- - - - - - - - - - - - - - - - - - - - - - - - - - -
You may get different results.
Everything will depend on the system involved.
- - - - - - - - - - - - - - - - - - - - - - - - - - -
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
STRING: USER-DEFINED
All VARIABLES after the value assignment
must end with a SEMICOLON
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$xyz = "STRING DELIMITED BY DOUBLE QUOTATION MARKS";
$str0 = 'STRING DELIMITED BY SINGLE QUOTATION MARKS';
$carÇ = 'STRING DELIMITED BY SINGLE "QUOTATION MARKS"';
$_alo = "STRING DELIMITED BY DOUBLE 'QUOTATION MARKS'";
$rquo = " » ";
$str01 = "1AnVXY234";
$str02 = "1234567";
// HEREDOC
$str03h = <<<EOD
Easy come, easy go.
If you can’t beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str04h = <<<EOT
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
// NOWDOC
$str03n = <<<'EOD'
Easy come, easy go.
If you can’t beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str04n = <<<'EOT'
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
echo $xyz . '<br><br>' . $str0 .
'<br><br>' . $carÇ .
'<br><br>' . $_alo . '<br><br>';
echo $rquo . '<br><br>' . $str01 .
'<br><br>' . $str02 . '<br><br>';
echo $str03h . '<br><br>' . $str04h . '<br><br>';
echo $str03n . '<br><br>' . $str04n;
?>
RESULT
- - - - - - - - - -
STRING DELIMITED BY DOUBLE QUOTATION MARKS
- - - - - - - - - -
STRING DELIMITED BY SINGLE QUOTATION MARKS
- - - - - - - - - -
STRING DELIMITED BY SINGLE "QUOTATION MARKS"
- - - - - - - - - -
STRING DELIMITED BY DOUBLE 'QUOTATION MARKS'
- - - - - - - - - -
»
- - - - - - - - - -
1AnVXY234
- - - - - - - - - -
1234567
- - - - - - - - - -
Easy come, easy go. If you can’t beat them, join them. Life begins at forty. Two heads are better than one.
- - - - - - - - - -
In PHP there are TWO types of variables: INTERNAL, (predefined). OF USER: (user-defined).
- - - - - - - - - -
Easy come, easy go. If you can’t beat them, join them. Life begins at forty. Two heads are better than one.
- - - - - - - - - -
In PHP there are TWO types of variables: INTERNAL, (predefined). OF USER: (user-defined).
- - - - - - - - - -
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
STRING: USER-DEFINED
All VARIABLES after the value assignment
must end with a SEMICOLON
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$xyz = "STRING DELIMITED BY DOUBLE QUOTATION MARKS";
$str0 = 'STRING DELIMITED BY SINGLE QUOTATION MARKS';
$carÇ = 'STRING DELIMITED BY SINGLE "QUOTATION MARKS"';
$_alo = "STRING DELIMITED BY DOUBLE 'QUOTATION MARKS'";
$rquo = " » ";
$str01 = "1AnVXY234";
$str02 = "1234567";
// HEREDOC
$str03h = <<<EOD
Easy come, easy go.
If you can’t beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str04h = <<<EOT
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
// NOWDOC
$str03n = <<<'EOD'
Easy come, easy go.
If you can’t beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str04n = <<<'EOT'
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
?>
<?= $xyz . '<br><br>' . $str0 .
'<br><br>' . $carÇ .
'<br><br>' . $_alo . '<br><br>' ?>
<?= $rquo . '<br><br>' . $str01 .
'<br><br>' . $str02 . '<br><br>' ?>
<?= $str03h . '<br><br>' . $str04h . '<br><br>' ?>
<?= $str03n . '<br><br>' . $str04n ?>
RESULT
The same result as the previous exercise.
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID CONSTANT EXAMPLES
STRINGS: INTERNAL
- - - - - - - - - - - - - - - - - - - - - - - - - */
echo PHP_VERSION;
// GETS THE ACTUAL PHP VERSION
echo PHP_EOL;
// SPECIFIES THE END OF LINE
echo PHP_DATADIR;
// SPECIFIES THE DATA DIRECTORY
?>
RESULT
- - - - - - - - - - - - - - - - - - - - - - - - -
7.4.11
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
H:\php
- - - - - - - - - - - - - - - - - - - - - - - - -
Your results for this exercise may be different.
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID CONSTANT EXAMPLES
STRINGS: USER-DEFINED
To establish a CONSTANT USER-DEFINED value
is necessary, before, to use de define statement:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
define('KONST01', 'Haste makes waste. ', FALSE);
// FALSE as default KONST01 ≠ konst01
// VERSIONS earlier than 8.0
echo KONST01 . '<br><br>';
define('KONST02', 'Haste makes waste. ', TRUE);
// TRUE as default KONST02 = konst02
// VERSIONS earlier than 8.0
// Warning: define(): Argument #3
// ($case_insensitive) is ignored
// since declaration of case-insensitive constants
// is no longer supported
// As of version 8.0
echo KONST02 . '<br><br>' . konst02 . '<br><br>';
// Fatal error: Uncaught Error:
// Undefined constant "konst02"
// As of version 8.0
echo KONST03;
// Warning: Use of undefined constant KONST03
// In all versions
?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
NUMBERS: INTERNAL
- - - - - - - - - - - - - - - - - - - - - */
echo $_SERVER['REQUEST_TIME'];
echo '<br><br>' . $_SERVER['REQUEST_TIME_FLOAT'];
// - - - - - - - - - - - - - - - - - - - - -
?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
NUMBERS: USER-DEFINED
All VARIABLES after the value assignment
must end with a SEMICOLON
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// INTEGER
$x01p = 220;
$x01n = -220;
echo '$x01p = ' . $x01p . '<br>$x01n = ' . $x01n . '<br><br>';
// FLOAT
$x02p = 123.456;
$x02n = -123.456;
echo '$x02p = ' . $x02p . '<br>$x02n = ' . $x02n . '<br><br>';
// CIENTIFIC NOTATION
$x03p = 1E19;
$x04p = 1.6e-19;
echo '$x03p = ' . $x03p . '<br>$x04p = ' . $x04p . '<br><br>';
// HEXADECIMAL NOTATION ->
// (20b)base 16 = (20B)base 16 = (523)base 10
$x05p = 0x20b;
$x06p = 0X20B;
echo '$x05p = ' . $x05p . '<br>$x06p = ' . $x06p . '<br><br>';
// OCTAL NOTATION -> (1023)base 8 = (531)base 10
$x07p = 01023;
echo '$x07p = ' . $x07p . '<br><br>';
// BINARY NOTATION -> (0011)base 2 = (3)base 10
$x08p = 0b0011;
// Available since PHP 5.4.0
echo '$x08p = ' . $x08p . '<br>';
?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - -
SOME VALID CONSTANT EXAMPLES
NUMBERS: INTERNAL
- - - - - - - - - - - - - - - - - - - - - - */
M_E;
// VALUE of e
M_PI;
// VALUE of PI
M_SQRT2;
// SQUARE ROOT of 2
?>
<?= M_E . '<br><br>' . M_PI . '<br><br>' . M_SQRT2 ?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID CONSTANT EXAMPLES
NUMBERS: USER-DEFINED
All CONSTANT after the value assignment
must end with a SEMICOLON.
To establish a CONSTANT USER-DEFINED value
is necessary, before, to use de define statement.
In PHP 8.0.0 the variables are
no longer case-insensitive, therefore,
all case-sensitive variables
are considered different.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// DECIMAL NOTATION
define('KONST03', 123456789);
echo 'KONST03 = ' . KONST03 . '<br><br>';
// OCTAL NOTATION ->
// (1023)base 8 = (531)base 10
define('KONST04', 0123);
echo 'KONST04 = ' . KONST04 . '<br><br>';
// HEXADECIMAL NOTATION ->
// (20b)base 16 = (20B)base 16 = (523)base 10
define('KONST05', 0X20B);
echo 'KONST05 = ' . KONST05 . '<br><br>';
// BINARY NOTATION ->
// (0011)base 2 = (3)base 10
define('KONST06', 0b0011, TRUE);
// Available since PHP 5.4.0
echo 'KONST06 = ' . KONST06 . '<br>';
echo 'konst06 = ' . konst06 . '<br><br>';
?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID CONSTANT EXAMPLES
NUMBERS: INTERNAL
- - - - - - - - - - - - - - - - - - - - - - - - */
// INTEGER
echo "Smallest INTEGER number = " . PHP_INT_MIN . '<br><br><br>';
// -2147483648(32 bit) or -9223372036854775808(64 bit)
// Available since PHP 7.0.0
echo "Largest INTEGER number = " . PHP_INT_MAX . '<br><br>';
// 2147483647(32 bit) or 9223372036854775807(64 bit)
// Available since PHP 5.0.5
echo PHP_MINOR_VERSION . '<br><br>';
// Current minor version of PHP
echo PHP_MAJOR_VERSION . '<br><br><br>';
// Current major version of PHP
// Available since PHP 5.2.7
// FLOAT
echo "Smallest FLOATING POINT number = " .
PHP_FLOAT_MIN . '<br><br>';
// Smallest floating point number
echo "Largest floating point number = " .
PHP_FLOAT_MAX . '<br><br>';
// Largest floating point number
// Available since PHP 7.2.0
?>
Another way to show a CONSTANT value.
If the constant is not defined an E_WARNING level error or NULL is generated.
<?php
mix constant ( str $name )
where,
$name = The name of the CONSTANT to be found the value
The CONSTANT name must be delimited by
double quotes or single quotes like STRING notation
?>
$name
The name of the CONSTANT to print the value.
EXERCISE
<?php
define('KONST03', 123456789);
define('KONST06', 'constant');
echo 'KONST03 = ';
echo constant('KONST03') . '<br>';
echo 'KONST06 = ';
echo constant('KONST06') . '<br><br>';
echo "Smallest INTEGER number = ";
echo constant ('PHP_INT_MIN') . '<br>';
// -2147483648(32 bit) or -9223372036854775808(64 bit)
// Available since PHP 7.0.0
echo "Largest INTEGER number = ";
echo constant ('PHP_INT_MAX') . '<br><br>';
// 2147483647(32 bit) or 9223372036854775807(64 bit)
// Available since PHP 5.0.5
echo "Smallest FLOATING POINT number = ";
echo constant ('PHP_FLOAT_MIN') . '<br>';
// Smallest floating point number
echo "Largest floating point number = ";
echo constant ('PHP_FLOAT_MAX') . '<br><br>';
// Largest floating point number
// Available since PHP 7.2.0
?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - -
Generally, Boolean data
is used in routines which
involve decision making
We will see how, in the
near future in this tutorial
- - - - - - - - - - - - - - - - - - - - - - - - - - */
$tr01 = true;
$TR01 = TRUE;
echo '$TR01 = ' . $TR01 . '<br><br>';
$fl01 = false;
$FL01 = FALSE;
define('tr01a', false, true);
echo 'tr01a = ' . tr01a;
define('FL01a', FALSE);
echo '<br><br>FL01a = ' . FL01a;
?>