Tools, FAQ, Tutorials:
Including Array Elements in Double-Quoted Strings in PHP
How Many Ways to Include Array Elements in Double-Quoted Strings?
✍: FYIcenter.com
There are 2 formats to include array elements in double-quoted strings:
Here is a PHP script example of different ways to include variables in double-quoted strings:
<?php $fruits = array('strawberry' => 'red', 'banana' => 'yellow'); echo "A banana is $fruits[banana].\n"; echo "A banana is {$fruits['banana']}.\n"; ?>
This script will print:
A banana is yellow. A banana is yellow.
"A banana is $fruits['banana'].\n" will give you a syntax error.
⇒ Accessing a Specific Character in String in PHP
⇐ Ways to Include Variables in Double-Quoted Strings in PHP
2016-10-13, 1348👍, 0💬
Popular Posts:
What Is HTML? HTML (HyperText Markup Language) is the standard markup language for creating Web page...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...
How To Control Vertical Alignment? By default, text in all table cells are aligned to the top vertic...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...
How to use the "rewrite-uri" Policy Statement for an Azure API service operation? The "rewrite-uri" ...