The special grammar for PHP
2016-08-26 10:50
218 查看
1.variable variables
$recipe = "spaghetti";
$$recipe = "& meatballs";
echo $recipe $spaghetti;
echo $recipe ${$recipe};
The result of both is the string spaghetti & meatballs.
2. global variables
$somevar = 15;
function addit() {
global $somevar;
$somevar++;
echo "Somevar is $somevar";
}
addit();
3. heredoc
<?php
$website = "http://www.romatermini.it";
echo <<<EXCERPT
<p>Rome's central train station, known as <a href = "$website">Roma Termini</a>,
was built in 1867. Because it had fallen into severe disrepair in the late 20th
century, the government knew that considerable resources were required to
rehabilitate the station prior to the 50-year <i>Giubileo</i>.</p>
EXCERPT;
?>
4. nowdoc
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
5. reference assignment
<?php
$value1 = "Hello";
$value2 =& $value1; // $value1 and $value2 both equal "Hello"
$value2 = "Goodbye"; // $value1 and $value2 both equal "Goodbye"
?>
<?php
$value1 = "Hello";
$value2 = &$value1; // $value1 and $value2 both equal "Hello"
$value2 = "Goodbye"; // $value1 and $value2 both equal "Goodbye"
?>
$recipe = "spaghetti";
$$recipe = "& meatballs";
echo $recipe $spaghetti;
echo $recipe ${$recipe};
The result of both is the string spaghetti & meatballs.
2. global variables
$somevar = 15;
function addit() {
global $somevar;
$somevar++;
echo "Somevar is $somevar";
}
addit();
3. heredoc
<?php
$website = "http://www.romatermini.it";
echo <<<EXCERPT
<p>Rome's central train station, known as <a href = "$website">Roma Termini</a>,
was built in 1867. Because it had fallen into severe disrepair in the late 20th
century, the government knew that considerable resources were required to
rehabilitate the station prior to the 50-year <i>Giubileo</i>.</p>
EXCERPT;
?>
4. nowdoc
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
5. reference assignment
<?php
$value1 = "Hello";
$value2 =& $value1; // $value1 and $value2 both equal "Hello"
$value2 = "Goodbye"; // $value1 and $value2 both equal "Goodbye"
?>
<?php
$value1 = "Hello";
$value2 = &$value1; // $value1 and $value2 both equal "Hello"
$value2 = "Goodbye"; // $value1 and $value2 both equal "Goodbye"
?>
相关文章推荐
- The key of special UI for the WoW
- PHP Tip: Getting the property count for an object
- Eclipse关闭No grammar constraints (DTD or XML schema) detected for the document警告
- ECM: The inventory location file for the special Windows NT case does not exist or is unreadable
- Eclipse关闭No grammar constraints (DTD or XML schema) detected for the document警告
- MaxDB & PHP - Ready for the Web!
- debug note-- nginx php-fpm : Error:The page you are looking for is temporarily unavailable.
- php xml-rpc 第三方工具使用 - The Incutio XML-RPC Library for PHP
- Eclipse里的No grammar constraints (DTD or XML schema) detected for the document警告
- linux64位编译php遇到configure: error: GD build test failed. Please check the config.log for details
- FileMaker Web Publishing: A Complete Guide to Using the API for PHP
- Special Characters for the Web: ISO 8859-1
- [Android] Eclipse Warning: No grammar constraints (DTD or XML schema) detected for the document
- Warning: No grammar constraints (DTD or XML schema) detected for the document
- Eclipse里的No grammar constraints (DTD or XML schema) detected for the document警告
- Some tips for grammar 'For all Entries' in the ABAP
- Setting the defaults for database access——使用createTables.php自动创建数据模型
- No grammar constraints (DTD or XML schema) detected for the document
- Warning: No grammar constraints (DTD or XML schema) detected for the document
- linux64位编译php遇到configure: error: GD build test failed. Please check the config.log for details