October 24 Morning PHP Object-oriented

Source: Internet
Author: User

Defining Arrays$attr=Array();$attr[0] = 1; indexed array$attr=Array(1,2,3,4); associative arrays$attr=Array("Code" = "P001", "name" = "Zhang San"); two-dimensional arrays$attr=Array(Array(),Array()); array traversal for loop traversal for($i= 0;$i<Count($attr);$i++)Count($attr) array length, only applicable to index traversal {$attr[$i];} The best use of foreach traversalforeach($attr  as $vall values are given to v{$v;}foreach($attr  as $k=$v)Keygive the K value a v{ .$k;$v;}$attr=Array(1,2,3,4,5,2);foreach($attr  as $k=$v) {if($v==3) {unset($attr[$k]); Delete Element}}$attr=array_values($attr); Re-indexVar_dump($attr);  each() and list () method traversalVar_dump( each($attr)); Remove the element that the current pointer points toList($a,$b)=$attr;Echo $b; pointer traversalEcho  Current($attr);Echo Key($attr);Next($attr);prev($attr);End($attr);Reset($attr);Var_dump(In_array(9,$attr)); Determine whether a value exists in an arrayVar_dump(Array_reverse($attr)); Flipping an arrayVar_dump(Array_unique($attr)); Go heavy$attr 1=Array(9,10);Var_dump(Array_merge($attr,$attr 1)); Merging ArraysArray_push($attr, 10); add element to array, return value is not a new arrayVar_dump($attr);$attr[]=11; Add elements to an arrayVar_dump($attr); object -oriented process-oriented$a= 10;$b= 15;Echo $a+$b; object-oriented1.What's called an object, everything is an object .2.what is called a class is made by the abstraction of many objectsclassren{describing human characteristic member variables by variables and methods Public $name; Public $sex; Construction Methodfunction__construct ($n){$sex=$n; Error$this Keywords,represents the object inside a class$this->sex =$nThe correct} member method generally requires access to the default public everywhere Public functionSpeak () {Echo"Talking Now";}}$r=NewRen ("Male"); Instantiating an objectVar_dump($r);$r 1=NewRen ("female");Var_dump($r 1); Construction method, always exists, if not write also existsVar_dump($r);$r->name = "John Doe"; Assign a valueEcho $r-Name: ValueVar_dump($r);$r-Speak ();$r 1=NewRen (); Instantiating an object$r 1->name = "Data";Var_dump($r==$r 1); access modifiers Public: On behalf of the public, accessible anywhereprotected: Represents a protected, accessible only in the class or subclass of the classPrivate: Represents a private, accessible only in this class

October 24 Morning PHP Object-oriented

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.