PHP Kernel Explorer: variable overview _php tips

Source: Internet
Author: User

The basic elements in modern programming languages are: variables, Process Control interfaces, functions, and so on. Can I write programs without using variables? This is clearly possible, for example:

Copy Code code as follows:

<?php
echo "Hello ANDHM";
?>

This program is very simple, output a string content.

Just as we can program using only binary, not using variables can do most of the work, do not use variables our program will lose great flexibility, variable allows us to store values for use elsewhere in the program, or to save new values by calculation. A variable has three basic attributes:

Name. The identifier for the variable. Like puppies, the owner may give these puppies a favorite name. Variable naming, PHP inherits the syntax style of Perl, and the variable begins with a dollar sign followed by the variable name. A valid variable name begins with a letter or an underscore followed by any number of letters, numbers, or underscores. PHP also supports complex variables, which are similar to the $ $a variable, which is interpreted two times. This provides PHP with a very flexible dynamic feature.

Type. The type of the variable, just like the breed of puppy dog, different breeds of puppies may not be the same, some are smart, some will shop and so on. In many static languages, variables are specified when they are defined and are not allowed to be changed while the program is running, so if you have a puppy that can be casually named, Will it wind up? This is what PHP is, a weak type language that can be arbitrarily given any type of value.
The value content. This is the specific content represented by the mark. It's like this kind of real puppy. You can give any puppy a name: Small seven, also in the programming language, you can give the variable the value it can represent range. At the same time, however, a variable can have only one value.

The letters that make up the variable name in PHP can be English letter a-z,a-z, or ASCII characters from 127 to 255 (0X7F-0XFF). Variable names are case-sensitive.

In addition to the variables themselves, we often have access to some concepts related to variables in PHP, such as constants, global variables, static variables, and type conversions. In this chapter we will describe these variables related implementations. These include the variable low-level storage structure of PHP itself and the implementation of weak type systems, and the conversion between these types.
First look at a section of PHP code:

Copy Code code as follows:

<?php
$foo = 10;
$bar = 20;
function Change () {
Global $foo;
$bar = 0;
$foo + +;
}
Change ();
Echo $foo, ', $bar;
?>

The running code will output 11 20.

But why is there such an output? How does a variable work inside PHP? How is the scope of the variable implemented? This is a discussion of the topic around variables, and we'll start with the most basic variable implementations here.

Values that are not variables in all programming languages can be changed. Think about the variables we've learned in math. Their values are also immutable. For example: X + y = 10; The values of the variables x and y are not changed. In a specific scenario, where only a particular value is represented in a formula, the value of a variable cannot be changed: this will produce as few side effects as possible, as is the case in the Erlang language, a functional programming language that is well worth learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.