Getting Started with PHP

Source: Internet
Author: User
Tags getting started with php variable scope

    • The PHP script can be placed anywhere in the document.
    • The PHP script begins with <?php and ends with?>:
    • PHP files usually contain HTML tags and some php script code.
    • PHP comments//#/* */Three kinds
    • PHP function is case insensitive, but variables in PHP are case sensitive
    • Using. To connect two strings in PHP
    • Echo Output string/value, auto match
    • Every line of code to; end
    • The variables in PHP must start with $, without the command to create the variable, and the variable will be created at the first assignment

Instance

<! DOCTYPE html>

    • Variable scope and function usage
    • To use global variables, write to the function block: global $a; You can use a outside of the function
Global scope function MyTest () {  //local scope  echo "<p> variable:</p> inside the test function";  echo "Variable x is: $x";//The output variable can be written in the string  echo "<br>";  echo "Variable y is: $x";} MyTest (); echo "<p> variable:</p> outside the test function"; echo "variable x is: $x"; echo "<br>" echo "Variable y is: $x";? >

PHP Static Keywords

Typically, all variables are deleted when the function finishes/executes. However, sometimes I need to not delete a local variable. Achieving this requires a bit of further work.

To do this, use the static keyword when you first declare a variable:

Instance
<?phpfunction myTest () {  static $x =0;  echo $x;  $x + +;} MyTest (); MyTest (); MyTest ();? >

Running an instance

Then, whenever the function is called, the information stored by the variable is the information contained in the last Call of the function.

Note: The variable is still a local variable of the function.


The $_get variable is an array of variable names and values that are sent by the HTTP GET method. [1] The $_get variable is used to collect values from a form method= "GET". Information sent from a form with a GET method is visible to anyone (displayed in the browser's address bar) and has a limit (up to 100 characters) to the amount of messages sent.Example<form action= "welcome.php" method= "Get" > Name: <input type= "text" name= "Name"/> Age: <input type= "text" n Ame= "Age"/> <input type= "Submit"/> </form> when the user clicks the Submit button, the URL is sent like this:/welcome.php?name=peter&age= The PNs "welcome.php" file can now get form data through the $_get variable (note that the name of the form field automatically becomes the ID key in the $_get array): welcome<?php echo $_get["name"]; <br/> are<?php echo $_get["age"];? >years old!
Query on Demand

Getting Started with PHP

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.