The php include statement contains a series of different files.

Source: Internet
Author: User

We have summarized

Every time you encounter INCLUDE, the php include statement contains the specified file. Therefore, you can use the INCLUDE statement in a loop structure to INCLUDE a series of different files.

  1. $ Files = array ('first. inc ','
    Second. inc ', 'third. inc ');
  2. For ($ I = 0; $ I items [$ artnr]
    + = $ Num;
  3. }
  4. // Take $ num articles of $ artnr
    Out of the cart
  5. Function remove_item ($ artnr, $ num ){
  6. If ($ this->Items [$ artnr]>$ Num ){
  7. $ This->Items [$ artnr]-= $ num;
  8. Return true;
  9. } Else {
  10. Return false;
  11. }
  12. }
  13. }
  14. ?> 

The above php include statement defines a class named Cart, which includes an associated array and two functions used to add and delete projects from cart.
Class is the original model of the actual variable. You need to use the new operator to create a variable of the desired type.

 
 
  1. $cart = new Cart;   
  2. $cart->add_item("10", 1); 

This creates a Cart Class Object $ cart. The add_item () function of this object is called to add 1 to the first item.
Class can be expanded from other classes. The expanded or derived class has all the variables and functions of the base class and what you define in the extended definition. This requires the extends keyword.

 
 
  1. class Named_Cart extends Cart {   
  2. var $owner;   
  3. function set_owner($name) {   
  4. $this->owner = $name;   
  5. }   

Here, the php include statement defines a class named Named_Cart, which inherits all variables and functions of the Cart class and adds a variable $ owner and a function set_owner (). The named_cart variable you created can now set the owner of carts. In the named_cart variable, you can still use the general cart function:

 
 
  1. $ncart = new Named_Cart; 
  2. // Create a named cart   
  3. $ncart->set_owner("kris"); 
  4. // Name that cart   
  5. print $ncart->owner; 
  6. // print the cart owners name   
  7. $ncart->add_item("10", 1); 
  8. // (inherited functionality from cart) 

The variable $ this in the function indicates the current object. You need to use $ this-> something to access all the variables or functions of the current object.
Class constructor is a function automatically called when you create a new variable of a certain type. A function with the same name as a class is the constructor.

 
 
  1. class Auto_Cart extends Cart {   
  2.  function Auto_Cart() {   
  3.  $this->add_item("10", 1);   
  4.  }   
  5.  } 

Here, the php include statement defines a class Auto_Cart, which adds a constructor for the Cart class to set project 10 for variable initialization every new operation. The constructor can also have parameters, which are optional. This feature makes it very useful.

 
 
  1. class Constructor_Cart {   
  2. function Constructor_Cart
    ($item = "10", $num = 1) {   
  3. $this->add_item($item, $num);   
  4. }   
  5. }   
  6.  // Shop the same old boring stuff.   
  7. $default_cart = new Constructor_Cart;   
  8. // Shop for real...   
  9. $different_cart = new 
    Constructor_Cart("20", 17);  

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.