First, you need to define the array, $attr = Array (directly to the elements) indexed arrays
Associative array $attr = Array ("one" =>1,2,3)
for ($i =0; $i <count ($attr); $i + +) iterating through an indexed array cannot traverse an associative array
The foreach traversal associated index can traverse
foreach ($attr as $k = $v)
{
$v;
}
Object-oriented classes and objects
Example:
$yuan = new Yuan ();
$yuan->banjing = 10;
echo $yuan->mianji ();
Var_dump ($yuan);
$this keyword represents the object inside a class
Build a great circle
$maxyuan = new Yuan ();
$maxyuan->banjing = 10;
Build a small Circle
$minyuan = new Yuan ();
$minyuan->banjing = 5;
echo $maxyuan->mianji ()-$minyuan->mianji ();
Class Yunsuan
{
Public $a = 10;
Public $b = 5;
Construction method
function __construct ($a 1, $b 1)
{
$this->a = $a 1;
$this->b = $b 1;
}
destructor, which executes when the object memory is released
function __destruct ()
{
echo "The object was released";
}
Private Function Jia ()
{
return $this->a+ $this->b;
}
function Jian ()
{
return $this->a-$this->b;
}
function Cheng ()
{
return $this->a* $this->b;
}
function Chu ()
{
return $this->a/$this->b;
}
}
Created objects
$y = new Yunsuan (10,5);
Var_dump ($y);
echo $y->chu ();
Access modifiers
Public, accessible anywhere
Protected is protected and can only be accessed in that class or subclass of that class
Private, accessible only in this class
The method at the beginning of __ becomes the Magic method in object-oriented
constructor function
1. Special wording: Method name Special
2. Execution time is special: When the object is created, it is executed.
Initialize a member inside an object
1211php Object Oriented