26
loading...
This website collects cookies to deliver better user experience
Disclaimer
This is the second post of a series, the main focus is my own growth on PHP. This isn't an informative article and what I say must be taken with a grain of salt. I'm always open for corrections and suggestions.
<?php
and ?>
respectively. This was the first thing that caught my attention, running functions inside the same file seemed so strange yet so easy to read. It is important to always finish a statement with a semicolon (;
).<!DOCTYPE html>
<body>
<p>This will be ignored by the parser and will be printed as is.</p>
<?php
// This is a comment and won't affect the code.
echo 'This will be printed out!'
?>
</body>
echo
is a language construct, a term that I researched about, but still would love to receive an explanation, that outputs expressions without additional newlines or spaces. This means that if you print something using it, the next echo will be in the same line without any space.<?php
echo 'Lorem ipsum';
echo 'dolor sit amet';
?>
Lorem ipsumdolor sit amet
.<?php
. It would be the same as using <?php echo '' ?>
.<?= 'Some random letters' ?>
" '
) or dollar signs without referencing variables or closing strings. You may use a backslash (\
) for this.echo 'This isn\'t that hard.';
$
) and are followed by a letter or an underscore, their names can be formed by any number and letter, also, they're case-sensitive. The variable also can't be named as $this
, as it refers to the object.<?php
$name = 'Vinícius';
echo $name;
?>
""
) instead of simple ones (''
), it is also recommended to use curly brackets ({}
) for better readability.<?php
$name = 'Vinícius';
echo "My name is {$name}!";
?>
<?php
$name = 'Vinícius';
$newName = &$name;
echo "My name is {$newName}! <br>";
$name = 'Ithalo';
echo "My name is {$newName}!";
?>