0
Can you tell me the difference between echo and Brackets?
<?php echo "OI {$nome}"?>
and without Brackets
<?php echo "OI ".$nome;?>
0
Can you tell me the difference between echo and Brackets?
<?php echo "OI {$nome}"?>
and without Brackets
<?php echo "OI ".$nome;?>
2
Response and example taken of this link:
1- echo
with Curly Brackets allows you to use the variable inside strings to separate the variable value of the text around it.
$verb = 'add';
echo "Present tense of this verb is $verb";
Imagine you want to add "ed" to the end of the variable without having to reset it:
echo "Past tense of this verb is $verbed";
This will generate an error, PHP will try to access the value of the variable "verbed".
But it would solve if using the following code:
echo "Past tense of this verb is {$verb}ed";
2- If $Verb is an array, an element can be accessed like this:
echo "Past tense of this verb is {$verb['past_tense']}";
3- If $Verb is an object and has a method called getPastTense()
which returns a string, can be used this way:
echo "Past tense of this verb is {$verb->getPastTense()}";
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
https://www.php.net/manual/en/language.types.string.php#language.types.string.Parsing
– Adir Kuhn
Why is it marked as duplicate? The answer to the question includes 3 items, the question of which this one was cited as duplicated only contains one of these 3 items.
– Ronaldo Araújo Alves
@Ronaldoaraújoalves Which two were missing that are not met by the explanation in the other answer?
– Woss
@Andersoncarloswoss I made some confusion, I looked again at the answer and it’s perfect. My fault.
– Ronaldo Araújo Alves
@Ronaldoaraújoalves Opa, I thought I had forgotten something :D
– Woss