PHP Learning 01

Source: Internet
Author: User
Tags array sort compact shuffle

  Set() When the private property of the class is used outside of the class, or when a property is not present, an error is set if __Set() method, then this method will be called * __Set(The member property name, the value of the member property to set) * __get () when the private property of a class is obtained outside of the class, an error is made when the property, or a property that does not exist, is called when the __get () method is set (the name of the member property) * __call () when calling the non-existent method of the class, it will error, if the modification method is defined, then call this method * __call (called method name, parameter of the method) * __callstatic (called method name, parameter of the method) * __clone () whenObjectCall this method when cloning * __clone (), the default parameter is$this,$that,$thisTo be cloned.Object,$thatAs the originalObject* __construct Constructor * __destruct destructor * __sleep (); WhenObjectCalled before serialization * __wakeup () called * __autoload (included class name) when deserializing a method that calls a class name, if the class is not included, an error is made, and when this function is defined, this function is called to dynamically load the class file __tostring ( ) When the direct output classObjectIf the method is defined, call this method * */class A {private$name; Private$age; Public Function __construct ($name,$age){$this->name =$name;$this->age =$age; } Public Function __Set($name,$value){$this-$name=$value; } Public Function __get ($name){if($name==' Fuck ')return"fuck!";if(Isset ($this-$name)){return$this->name; }Else{returnNULL; }} public Function __call ($name,$args){Echo$name,"Mothod does not exist."; Var_dump ($args); } public static function __callstatic ($name,$value){Echo" static method $name not Present"; } public function__clone() {$this->name ="I was cloned."; } public function__sleep() {       //Echo"is being serialized";returnArray (name); }//RegenerateObject, the public function is called__wakeup() {$this->name ="Zhang San";$this->age =234; } public function__tostring() {return"A"; }}//$a= New A ("Zhang San", A);//Echo$a->name;//$a->name ="Zhang San";//Echo$a->name;//$a->get ("Xue",3,"SF") ;//$a 1= Clone$a;//Echo$a->name,"
",$a 1->name;//$p _str= Serialize ($a);//Echo$p _str;//$a 2= Unserialize ($p _str);//var_dump ($a 2);//function __autoload ($classname){//include $classname.". php";//}//Echo$a 2->fuck;//a::ha ();/* *1.EchoAnd the difference between print *Echois a statement, not a function, without parentheses, can output multiple values, no return value, cannot output an array andObjectcan only output simple types, such as int,string * print is a statement, not a function, without parentheses, can only output a value, there is a return value1, you cannot output arrays andObject, you can only output simple types, such as int,string *2. Print_r () and Var_dump () * PRINT_R () are functions that can output composite types and simple types, such as int float, string, array object, when outputObjectWhen an organization is represented as object{}, when the output * array is represented as an array () * Var_dump () is a function, the content of the output variable, type, length, can be output simple type, compound type, commonly used to debug *3. printf is a function, similar to the C language, formatted string output *4The. sprintf function, like the C language, returns a formatted string after a formatted string does not output * *///PRINT_R (3.55);//$arr= Array ("Xue",3);//Print_r ($arr);//Var_dump ($arr);//$NB= sprintf ("%s is a%d crane","haha",3);//Echo$NB*/* * Get file content mode *1. file_get_contents (); * *///$txt= File_get_contents (' Data.txt ');//Echo$txt;//$file= fopen ("Data.txt","R");// while(!feof ($file)){//$line= Fgets ($file);// //Echo$line;// //}// while(!feof ($file)){//$char= Fgetc ($file);//Echo$char//}/* * strlen () The difference between the He mb_strlen * Both are functions that seek the length of a string * in the strlen just get the number of bytes in the string, the Chinese characters cannot be handled correctly * when encoding for GB2313, a kanji account2Bit, when for utf-8When encoding, a Chinese character occupies3Bit * Mb_strlen () can handle Chinese characters correctly, the second parameter is the encoded type, the default is utf-8, the default is PHP internal code, you can use Mb_internal_encoding () to see * Mb_strlen () is not the PHP core function, need to load the extension library to use, in php.in extension ="Php_mb_string.dll"*///$str="Daiyu 123f";//EchoStrlen$str); OutputTen//EchoMb_strlen ($str,' UTF-8 '); Output6//EchoMb_internal_encoding ();//Output iso-8859-1* * PHP Array function * Key name and value of array *1The. Is_array () Determines whether the array is returned true, not the returnfalse, similar to Is_int (); Is_float (); *2. Array explode (string$delimiter, string$string[, int$limit]) This function splits the string into arrays *3. String Implode (string$glue, array$pieces) to split the array into strings *4. Array_values () returns all the values of the array, please create a number for itIndex*5. Array Array_keys (array$input[, Mixed$search _value= NULL [, bool$strict=false]] ) *6. Array_key_exists () Retrieves the specified key name orIndexis in the array, there is a returntrue, or returnfalse*7. Array_flip () Exchange the key name and value of the array, and the last key value if the same value exists *8. Array_search () Searches for the given value in the array, returns False if there is a corresponding key name returned *9Retrieves whether a value exists in the array, there is a returntrue, there is no return false *Ten. Isset ($arr[' Apple '] detects whether the specified key name is known to exist in the given array, there is a returntrue, or returnfalse* The internal pointer of the array * current ($arr); Returns the current cell Pos in the array ($arr); Returns the current cell key in the array ($arr); Returns the key name of the current cell in the array prev ($arr); Rewind the internal pointer in the array back to a next ($arr); Moves the inner pointer in the array forward one end ($arr); Point the inner pointer in the array to the last unit reset ($arr; Point the inner pointer in the array to the first cell * each ($arr); Returns the key name and value of the current pointer cell of the array, in the form of a new array, and the pointer of the current array moves forward one step, and if the last cell of the array is reached, the last cell is returned as an array of four cells with the key name >,key and value. Unit0And key contain the key name of the array element,1and value contain data. * List ($key,$value); is not a real function, is a language structure, gets the key name and value of the current element of the array, and assigns a value to the variable, list can only be used for no key name andIndexArray * * * Extract () Import variables into the current symbol table from an array * check each key name to see if it can be used as a valid variable name and also check for conflicts with the variable names already in the symbol table. * Compact () changes the variable to the fragment and fill of the array * array * Array_slice takes a section of * Array_slice in the array ($array, int offset,[int length,false|true]); * If the offset is negative, the number starts at the end of the array * If the length is negative, then the sequence terminates at such a distance from the end of the array * array Array_splice (array &$inputInt$offset[, int$length=0[, Mixed$replacement]]) * Delete a segment of an array, according to offset and length, you can replace the deleted unit with replacement, the number of replacements and the number of units replaced is the same, if the array, the key name * is not preserved, only replace the value, or a string, if there is no deleted unit, Then the replacement variable will be inserted into the offset position * * Split multiple arrays * Array_chunk (array,size,[true|false]) * Splits an array into multiple arrays, each array having an element quantity of size,size less than1will be an error, the element of the last array may be less than size, the default isfalse, the original array will be discarded.Indexor key Name * re-established from0Number of startsIndexFortrue, keep the original key name orIndex* * Array padding * ARRAY_PAD (array,length,value); * Fill the array with value to length, * if length is less than or equal to the size of the array, * If length is a negative number, the left padding * array and Stack * Array_push (array,value,,,); * Press one or more values into the array stack, returning the number of elements of this array * ARRAY_POP (array); * Returns the stack top element of an array, if the array is empty or not an array, returns a null * * array with the queue * Array_shift (array); * The first element of the array is returned, the number of elements in the array is reduced by one, the following elements move forward, and the number key names are from0Start re-engineering, association key name is not changed * If the array is empty, or not a group, then null * array_unshift (Array,value,,,) is returned; * Insert values at the beginning of the array, all numbersIndexwill be restarted from0Start technology, Associate key name unchanged * * Array sort * Key value sort * Sort (array,[]); Sorts the values of the array from small to large, and the operation returns successfullytrue, or returnfalse* Ignore array ordering of key names * Rsort (array[],,), sort the values of the array from large to small, the operation returned successfullytrue, or returnfalse* Ignore array ordering of key names * Usort (array,funcname); Call user-defined function to sort the array * Ignore the numeric sort of the key name * * Asort () keep the value of the key name sorted * Arsort () preserve the numeric ordering of the key name * Uasort ( * ========= * Key Name sort * Ksort () sorted by key name, mainly used for associative array * Krsort () sorted in reverse order of key Name * Uksort () Custom Function Sort * ========= * Sort by natural sort * Natso RT (); Natural sort * Natcasesort () natural sort, ignoring case * * The calculation of the array * Array_sum () computes the merging of the array element and the * array * array_merge (ARRAY1,ARRAY2); The key name is re- NewIndex* Array1+array2 for the same key name only keep the first * if you want to completely preserve the original array and just want to append the new array to the back, use the + operator * array_merge_recursive () to recursively merge the array * If the input array has the same string key name , the values are merged into an array, which recursively goes down, so if a value is itself an array, the function will merge it into another array according to the corresponding entry. However, if the array has the same array key name, the latter value will not overwrite the original value, but is appended to the back. * * The difference set of the array * Array_diff (array1,array2,array3,,,); Returns the element in Array1 but not in the other array * ARRAY_DIFF_ASSOC (array1,array2,array3 ...); Returns an element in Array1 but not in another array, the key name is also compared, only the key name and the key value are the same when the intersection of the * * array * array_intersect (array1,array2,,,); Returns the intersection of the array * array_intersect_as Soc (array1,array2,,,); Returns the intersection of the array, the key name is also compared * * Other array functions * range (START,MAX,STEP); Create an array of start to Max Range, step step, default to1* Array_unique () Drop the duplicate value in the array * array_reverse (); Invert the array, if the second argument istrueThe key name is reserved * Array_rand (array,size), the key name of one or more cells in the array is returned randomly, and if multiple, an array with multiple key names is returned * Shuffle (array); The elements of the array are scrambled, returning false or True * * * *///var_dump (Is_array (3));$arr= Explode (",","i,am,hello,3");p Rint_r ($arr);EchoImplode ($arr);//array_values ()$arr= Array_values (Array (' name '=' Daiyutage ',"Age"= -));p Rint_r ($arr);$arr= Array_keys (Array (' name '="Daiyutage","Age"= -));p Rint_r ($arr); Var_dump (Array_key_exists (' name ', Array ("Name"="Daiyu")); Var_dump (Array_flip ((array) ("a"=1,"B"=1,"DDD"= -))));Echoinch_array ("Daiyutage", Array ("Name"="Daiyutage"));$arr= Array ("Name"=1);EchoIsset$arr[' name ']);$foo= Array ("Robert"="Bob","Seppo"="Sepi","Name"=3324);$bar= each ($foo);p Rint_r ($bar);$bar= each ($foo);p Rint_r ($bar);$info= Array ("Name","haha");unset($a); List ($a[0],$a[1]) =$info;//print_r ($a);////$name="Diayutage";//extract (Array (//"Name"="Xue",//"Age"= A,//"School"="Lut"), Extr_prefix_same,' WX ');//Echo$name," ","$age"," ","$school"," ",$Wx _name;//textbook,1,2,3, the book read times, its righteousness from now on//compact$firstname="Peter";$lastname="Griffin";$age= -;$color="Red";$rs= Array ("Color","FX");//$result= Compact ("FirstName","LastName","Age",$rs);//print_r ($result);$arr= Array ("a","XX"="B",6="C","D","E");//print_r (Array_slice ($arr,2,-1,true);//Array_splice ($arr,1,-4,"xxxxx");//Print_r ($arr);//print_r (Array_chunk ($arr,2,false));//print_r (Array_pad ($arr,-Ten, -));//print_r (Array_push ($arr,"Daiyutage","FFF"));//EchoArray_pop ($arrs);//EchoArray_shift ($arr); Array_unshift ($arr, Array ("HASDF","SF"));$fruits= Array ("Lemon","SDFSF"="Orange","Banana","Apple"); Rsort ($fruits); function cmp ($a,$b){return$a==$b?0:$a<$b?-1:1;} //$BRR= Array ("FSF","FS"=3,Ten=2,4=244,3244);//ksort ($BRR);//print_r ($BRR);//print_r (Array_merge ($fruits,$BRR) and/or the key name will be renewed in a continuous mannerIndex//$a= Array (3="Red","Hello","Hello");//$b= Array ("Red","FE");//print_r (Array_intersect_assoc ($a,$b);//var_dump (Range (0, A,9));//print_r (Array_reverse ($fruits));//print_r (Array_rand ($fruits);//(Shuffle ($fruits);//Print_r ($fruits);///* * Time zone setting * Date_default_timezone_Set() Set the time zone, the time zone is incorrect will throw an error e_warning instead of E_strict. Case insensitive * Date_defalut_timezone_get () Get time zone * China time zone for Asia/shanghai or PRC * *///EchoDate_default_timezone_get ();//error_reporting (E_all);//date_default_timezone_Set("PRC");//EchoDate_default_timezone_get ();///* cgi,php_mod,fastcgi Difference * CGI Universal Gateway Protocol * When a client requests a server, the server fork a process, Execute the PHP.CGI program to parse the PHP page, resolve the process to destroy, return to the server, * each request process,fork-> execution, destruction, inefficient, more expensive system resources * PHP_MOD * PHP interpreter starts with the Apache server in the form of a module, using the same process * FastCGI * CGI enhanced version, equivalent to a middle tier, using a process, client-server->fastcgi->php to explain the instance, FASTCGI uses a process to host memory and creates multiple CGI instances * Apache communicates with fastcgi for TCP communication, that is, fastcgi can be native, or it can be used for remote host * Apache-to-CGI communicationinter-process communication, must be the same host * Small summary: CGI: Need to open a number of processes; FastCGI: An additional process needs to be started; Php_mod: no additional processes need to be opened because the PHP parser is integrated into the Web server and is in the same process as the Web server. * * Php_mod Configuration method * in Apache, httpd.conf *1LoadModule Php5_module"C:/php5/php5apache2_2.dll"About Line1272Phpinidir"C:/php5/php.ini"3Modify Configuration4DirectoryIndex index.html index.php//Additional index.php5AddType application/x-httpd-php. PHP//line408Add * CGI configuration mode * * *///error_reporting (E_all);//setcookie ("haha");/* * Cookies and Session * cookie[' Login '] =true; * A visit * session box open * session[' Login '] =true; * B Access * Session box open * session[' Login '] =true; * Session in memory, if you do not distinguish between each client session, then the session will not be able to use * so you need to associate each request session with its client * method: * When the server is first requested, the server generates a session_id, * The session_id is sent to the browser via HTTP headers, and the browser is saved in the cookie that stores the session_id locally * When requesting the server again, the browser sends this cookie, and the server receives the Session_ in the local cookie ID to access the session of this client * * When the cookie is disabled, how to use session * PHP default has two kinds of session delivery method *1. Cookies *2. URL such as. php?sid=xxx, or post submission method, manually add Sid * URL via URL by setting php.ini parameter, automatically add to URL * session.use_cookie=1* session.use_>0* session.use.trans_id=1* Then PHP will automatically add phpsession=xxxx to the URL * *3. File save SID, the first page to save SessionID in the file, the second page from the file to take SessionID in determining whether to log in *4. Database save SID, same as file principle * * When the cookie is disabled, no more cookies are sent to the server when browsing the request, then the server will not receive the cookie=phpsession and cannot use the session * URL * After opening the session on the previous page, use session_id () to get session_id, and then Get/post way to the next page * The second page is set session_id () with this sessio_id, then turn on Session_ Start (), you can use the session in front of you * Note: session_id () must be called before session_start () * * * */session_start ();$_session[' Login '] ="Daiyutage";//$sid= session_id ();Echo"another page";

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above introduction of PHP Learning 01, including include, interprocess communication, object, index, static method aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.