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.
- $ Files = array ('first. inc ','
Second. inc ', 'third. inc ');
- For ($ I = 0; $ I items [$ artnr]
+ = $ Num;
- }
- // Take $ num articles of $ artnr
Out of the cart
- Function remove_item ($ artnr, $ num ){
- If ($ this->Items [$ artnr]>$ Num ){
- $ This->Items [$ artnr]-= $ num;
- Return true;
- } Else {
- Return false;
- }
- }
- }
- ?>
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.
- $cart = new Cart;
- $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.
- class Named_Cart extends Cart {
- var $owner;
- function set_owner($name) {
- $this->owner = $name;
- }
- }
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:
- $ncart = new Named_Cart;
- // Create a named cart
- $ncart->set_owner("kris");
- // Name that cart
- print $ncart->owner;
- // print the cart owners name
- $ncart->add_item("10", 1);
- // (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.
- class Auto_Cart extends Cart {
- function Auto_Cart() {
- $this->add_item("10", 1);
- }
- }
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.
- class Constructor_Cart {
- function Constructor_Cart
($item = "10", $num = 1) {
- $this->add_item($item, $num);
- }
- }
- // Shop the same old boring stuff.
- $default_cart = new Constructor_Cart;
- // Shop for real...
- $different_cart = new
Constructor_Cart("20", 17);