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.
It is used in the presentation of data.
This language construction 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 or 127.0.0.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 = " » ";
$str02a = "1AnVXY234";
$str02b = "1234567";
// HEREDOC
$str02c = <<<EOD
Easy come, easy go.<br>
If you can’t beat them, join them.<br>
Life begins at forty.<br>
Two heads are better than one.
EOD;
$str02d = <<<EOT
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
// NOWDOC
$str02e = <<<'EOD'
Easy come, easy go.
If you can’t beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str02f = <<<'EOT'
In PHP there are TWO types
of variables:<br>
INTERNAL, (predefined).<br>
OF USER: (user-defined).
EOT;
echo $xyz . '<br><br>' . $str0 . '<br><br>' .
$carÇ . '<br><br>' . $_alo . '<br><br>';
echo $rquo . '<br><br>' . $str02a . '<br><br>' .
$str02b . '<br><br>';
echo $str02c . '<br><br>' . $str02d . '<br><br>';
echo $str02e . '<br><br>' . $str02f;
?>
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 = " » ";
$str03a = "1AnVXY234";
$str03b = "1234567";
// HEREDOC
$str03c = <<<EOD
Easy come, easy go.<br>
If you can't beat them, join them.<br>
Life begins at forty.<br>
Two heads are better than one.
EOD;
$str03d = <<<EOT
In PHP there are TWO types
of variables:
INTERNAL, (predefined).
OF USER: (user-defined).
EOT;
// NOWDOC
$str03e = <<<'EOD'
Easy come, easy go.
If you can't beat them, join them.
Life begins at forty.
Two heads are better than one.
EOD;
$str03f = <<<'EOT'
In PHP there are TWO types
of variables:<br>
INTERNAL, (predefined).<br>
OF USER: (user-defined).
EOT;
echo $xyz . '<br><br>' . $str0 . '<br><br>' .
$carÇ . '<br><br>' . $_alo . '<br><br>';
echo $rquo . '<br><br>' . $str03a . '<br><br>' .
$str03b . '<br><br>';
echo $str03c . '<br><br>' . $str03d . '<br><br>';
echo $str03e . '<br><br>' . $str03f;
?>
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
?>
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
echo KONST01 . '<br><br>';
define('KONST02', 'Haste makes waste. ', TRUE);
// TRUE as default KONST02 = konst02
echo KONST02 . '<br><br>' . konst02 . '<br><br>';
echo KONST03;
?>
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.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// 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>';
?>
RESULT
When running this exercise it is verified that in version 7.4.XX of PHP no error is shown, however in version 8.0.XX there is a Warning and a Fatal error.
So check it out.
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID CONSTANT EXAMPLES
NUMBERS: INTERNAL
- - - - - - - - - - - - - - - - - - - - - - - - */
// INTEGER
echo "Smallest INTEGER number =<br>= " .
PHP_INT_MIN . '<br><br><br>';
// -2147483648(32 bit)
// or
// -9223372036854775808(64 bit)
// Available since PHP 7.0.0
echo "Largest INTEGER number =<br>= " .
PHP_INT_MAX . '<br><br>';
// 2147483647(32 bit)
// or
// 9223372036854775807(64 bit)
// Available since PHP 5.0.5
echo 'PHP_MINOR_VERSION =<br>= ' .
PHP_MINOR_VERSION . '<br><br>';
// Current minor version of PHP
echo 'PHP_MAJOR_VERSION =<br>= ' .
PHP_MAJOR_VERSION . '<br><br><br>';
// Current major version of PHP
// Available since PHP 5.2.7
// FLOAT
echo "Smallest FLOATING POINT number =<br>= " .
PHP_FLOAT_MIN . '<br><br>';
// Smallest floating point number
echo "Largest floating point number =<br>= " .
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;
?>
RESULT
When running this exercise it is verified that in version 7.4.XX of PHP no error is shown, however in version 8.0.XX there is a Warning.
So check it out.
EXERCISE
<?php
class test02
{
public $var03 = 'Alea jacta est';
public $var04 = 'Luck is on';
}
$obj02 = new test02;
echo $obj02->var03 . '<br>';
echo $obj02->var04;
?>
RESULT
Alea jacta est
Luck is on
This exercise is just an example.
Classes and Objects must be studied in a separate chapter.
EXERCISE
<?php
$v13a = 5.455_052e-10;
// float
$v13b = 300_482_381;
// decimal
$v13c = 0xBBFF_3E48;
// hexadecimal
$v13d = 0b0101_1111;
// binary
// Representations available since the PHP 7.4.0
echo '$v13a = ' . $v13a;
echo '<br><br>$v13b = ' . $v13b;
echo '<br><br>$v13c = ' . $v13c;
echo '<br><br>$v13d = ' . $v13d;
?>
RESULT
$v13a = 5.455052E-10
$v13b = 300482381
$v13c = 3154067016
$v13d = 95
It does not matter what the base of the VARIABLE was originally defined, as the result will always be expressed in base 10.
EXERCISE
<?php
echo 'PHP: ' . PHP_VERSION . '<br><br>';
$case_insensitivef = false;
$case_insensitivet = true;
echo($case_insensitivef);
echo '<br><br>';
define("const01", 'Constante 01', $case_insensitivef);
echo const01 . '<br><br>';
define("CONST01", 'CONSTANTE 01', $case_insensitivef);
echo CONST01 . '<br><br>';
echo($case_insensitivet);
echo '<br><br>';
define("const01", 'Constante 01', $case_insensitivet);
echo const01 . '<br><br>';
define("CONST01", 'CONSTANTE 01', $case_insensitivet);
echo CONST01 . '<br><br>';
?>