Learn PHP in class

Source: Internet
Author: User
Tags getting started with php learn php

Getting Started with PHP

A. Variable

Variables are used to store values, we command the server to work, often need to produce some data, need to be stored temporarily for easy access. We can also understand that the variable is like a shopping bag, we can be used to install apples, durian (of course, can also be used to install roses), it is important to note that in general, a variable can only be loaded with one (not too greedy) value, unless it is a compound variable (described later in the variable type), when we put an apple When you put it in the durian, the Apple is replaced and the banana is put in, then the durian is replaced.

The variable is like a monkey picking corn, only one of the last hands left!

<?php
$var = "Everyone to learn PHP";
Echo $var;
echo "<br/>";
$var = "Learn PHP on the Web";
Echo $var;
?>

Two. How to define Variables

The definition variable is the memory of the server (the memory of the server, we can use it as a large warehouse) to request space (which we can understand as a sub-warehouse) to store the data. At this point we need to use the variable name (that is, the name of the sub-warehouse) and the value of the variable (need to store things, apples, durian, bananas can be). Ji Xiaolan to his study took a name "read Micro Cottage", this "read Micro Cottage" is the variable name, the study put things is the variable value.

Where variable names must be $ identified by symbols;

Code:

<?php
$var _name = "Apple";
$n = 10;
Var_dump ($var _name);
Var_dump ($n);
?>

Three. Naming rules for variable names

In addition to the need to "$" (must be taken) to identify outside

1. Variable names must begin with a letter or underscore "_", such as "$_name", "$name", "$name 2", etc., but "$9name" is not correct.

2, the variable name can only be composed of letters, numbers, and "_", but also contain Chinese characters. such as "$_qq", "$QQ 308", "$my _apple", "such as" $name I Wait ", but" $name * "is wrong.

3. Variable names are not allowed to contain spaces. When the variable name consists of multiple words, it is recommended to use "_" to separate (for example $my _apple), commonly known as the underscore method, or start with a capital letter such as $myApple, commonly known as camel-named (also known as the Hump name).

In particular, it is important to note that in PHP variable names are case-sensitive, such as "$my _book" and "$my _book" represent two different variables.

<?php
$my _book = "my lowercase book";
$my _book = "My book in uppercase";
echo $my _book;
echo "<br/>";
echo $my _book;
echo "<br/>";
$my _book = "This miracle is going to happen";
echo $my _book;
echo "<br/>";
?>

Learn PHP in class

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.