Indirect reference of variables, connection string and connection assignment operator of PHP entry variables_PHP tutorial

WBOY
Release: 2016-07-13 10:35:34
Original
1100 people have browsed it

【1】Indirect reference of variable:

<?php 
 $a = 'b';
 $$a = '123'; 
 echo $b; 
?>
Copy after login

The above output is 123

We can see that there is an extra $ in the second line of code, and the variable is accessed through the specified name. The specified name is stored in $a('b'), and the value of this variable $b is changed to 123. Therefore, such a variable of $b is created and assigned.

You can increase the number of references arbitrarily by adding an additional $ mark in front of the variable.

【2】Concatenate strings: Use the concatenation operator, that is, the period (.) in the English state, to concatenate the strings into a merged new string.

<?php 
	$a = 'PHP5' ; 
	$b = '功能强大' ; 
	echo $a.$b; 
?>
Copy after login

In order to let us understand the connection string better, we changed it based on the above example and turned it into something like this (PHP5: Powerful 2014)

In this example we see quotes, spaces and numbers added. Below we will use two methods to write, and you will find out the specific differences yourself:

<?php 
	$c = $a.': '.$b.' 2014';
	$c = $a.': '.$b.' '.2014;
?>
Copy after login

【3】Connection assignment operator: If you only connect one value to another value, you can use the connection assignment operator (.=). The following two statements are equivalent:

<?php 
	$title = $title . $subtitle; 
	$title .= $subtitle; 
?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743387.htmlTechArticle【1】Indirect reference of variables: ?php $a = 'b'; $$a = '123' ; echo $b; ? The above output is 123. We can see that there is an extra $ in the second line of code, and it is accessed through the specified name...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!