PHP $$ role and use of symbols

$$ defined in the action symbol php

In PHP single variable dollar sign ($ str), str represents a common variable named, which can store the value of the string, integer, array, any other Boolean type.

Variable double dollar sign ($$ str): represents a variable variable (also called a reference variable) for storing a value of $ str.

Variable variables: variable name refers to a variable can dynamically set up and use, use a normal variable is set with a statement.

Note: Method functions and classes in PHP, superglobals variable variables can not be used. $ This variable is a special variable that can not be dynamically referenced.

Example:

$$str;

$$ use the symbol php

Sample code:

<? the php
 $ the var = 'By word hello You!' ;
the str $ = 'the var' ;
echo out the  $ the str ;
echo out the $ $ the str ;
?>

Output:

was 
hello word !

Description:

1, the variable value string var $ str

2, $$ str variable is a variable, $ str var value is equal to $ var $$ str

Example 2:

? < PHP
 $ A = 'B' ;
 $ B = 'C' ;
 $ C = 'A' ;
 echo  $ A ; // Output: B 
echo  $ B ; // Output: C 
echo  $ C ; // Output: A 
echo $ $ A ; // output: c 
echo $$ $ A ; // output: A 
echo $$$ $ A ; // output: b 
>?

Example 3:

Dynamic class instantiation

<?php
class data_user {
 function age(){
 return '10';
 }
}
var $ = 'data_user' ;
 $ A = new new  $ var ;
 echo  $ A -> Age ();
 ?>
 // output: 10

Guess you like

Origin www.cnblogs.com/-mrl/p/11711697.html