What do the arrows "," and "=" in PHP code mean?

Source: Internet
Author: User

A class is a complex data type, and this type of data mainly has attributes, methods, and two kinds of things.

Properties are actually variables that can hold data, which can be integers, strings, arrays, and even classes.

Methods are actually functions that are used to accomplish certain functions.

The properties and methods that refer to a class use the-a symbol.

Here is an example applet:
<?php
Define class Cart
Class Cart {
var $items; Items in the shopping cart

Add $num $artnr items to your shopping cart

function Add_item ($ARTNR, $num) {
$this->items[$artnr] + = $num;
}

Remove $num $artnr items from your shopping cart

function Remove_item ($ARTNR, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr]-= $num;
return true;
} elseif ($this->items[$artnr] = = $num) {
unset ($this->items[$artnr]);
return true;
} else {
return false;
}
}
}

Example inheritance definition class Named_cart
Class Named_cart extends Cart {
var $owner;

function Set_owner ($name) {
$this->owner = $name;
}
}

Using the code of the class
$ncart = new Named_cart; Create a new shopping cart with a name
$ncart->set_owner ("Kris"); Give the shopping cart a name
Print $ncart->owner; Output the name of the owner of the cart
$ncart->add_item ("10", 1); (features inherited from the shopping cart class)
?>

This arrow can also be a function in the calling class such as Class A {function B () {echo ' A ';}} $a =new A; $a->b (); Output: A
There is also an arrow like this, which defines an array for example $array 1=array (' A ' =>5, ' B ' =>6); while ($arrayitem =each ($array 1)) {extract ($arrayitem); Echo (' <br/> '. $key. ' = '. $value); } Output: A=5 b=6

What do the arrows "," and "=" in PHP code mean?

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.