Home >Backend Development >PHP Tutorial >Getting Started with PHP Variables_PHP Tutorial

Getting Started with PHP Variables_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:37900browse

A variable is a container used to temporarily store values. These values ​​can be numbers, text, or much more complex data.

PHP has 8 types of variables.

It includes 4 scalar (single value) types - string (character), integer, floating point (decimal) and Boolean (TRUE or FALSE);

Two non-scalar (multi-valued) types - arrays and objects, as well as resources (which you will see when interacting with the database) and NULL (which is a special type that does not have any values).

================================================== =============================

PHP syntax rules:
1. The name of a variable—also called its identifier—must start with a dollar sign ($), for example, $name.
2. Variable names can contain a combination of letters, numbers and underscores, for example, $my_report1.
3. The first character after the dollar sign must be a letter or underscore (not a number).
4. Variable names in PHP are case-sensitive. This is a very important rule. This means that $name and $Name are distinct variables.

FAQ:

First, you can use the equal sign (=) (also called the assignment operator) to assign a value to a variable.

Second, variables can be printed without quotes; or variables can be printed within double quotes; but cannot print variables within single quotes .

<?php
	echo $name;				//无需引号即可打印变量
	echo "Hello, $name";	//在双引号内打印变量
	echo 'Hello, $name';	//在单引号内打印变量[会报错]
?>

================================================== =============================

【1】The most important consideration when creating variables is to use a consistent naming pattern. Some programmers prefer to use all lowercase letters for variable names, with underscores separating words ($first_name); some prefer to use an initial capital letter, such as: $FirstName (i.e. camel case).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/742587.htmlTechArticleVariables are containers used to temporarily store values. These values ​​can be numbers, text, or much more complex data. PHP has 8 types of variables. It includes 4 scalar (single value) type characters...
Statement:
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