If we know the name of the array element, it's easy.Press the key to delete the specified array element from the array. The code is as follows:Copy code $ Barray = array ('a' => 1, 'B' => 2, 'wod '=> 3, 'C' => 4, 'ABC' => 5 );$ Del = 'B ';Unset (
Cause analysisThis problem is generally caused by undefined variables.Example The code is as follows:Copy code If ($){Echo $;}Else{} // Prompt: Notice: Undefined variable: a in E:/www/test. php on line 5 The code is as follows:Copy code //
String; judge whether the string is null; output judgment; you can modify it The code is as follows:Copy code If (empty ($ C_char) return false; // whether it is setIf ($ C_char = '') return false; // whether it is null Use = ""Example The
If the PHP setting option register_globals is on, the related variable names will also exist. From PHP 4.2.0, the default value of register_globals is set to off.Assume that the file upload field is named userfile. The name can be named at will.$ _
Simple session creation The code is as follows:Copy code Session_start ();$ Username = "nostop ";Session_register ("username ");?> In this example, we registered a variable named username with the value of nostop to the session.Read
The defined () function checks whether a constant exists.If a constant exists, true is returned; otherwise, false is returned. The code is as follows:Copy code If (defined ('myconstant ')){Echo "constant MYCONSTANT exists ";} Else {Echo
It's a very simple php Tutorial, and it's also an entry-level thing, so I won't talk much about it.Code The code is as follows:Copy code // Description: Solution for deleting non-empty directoriesFunction removeDir ($ dirName){ If (! Is_dir ($
If successful, the time is returned in Unix timestamp format. If it fails, false is returned.Filemtime (string filename)Returns the time when the file was last modified. If an error occurs, FALSE is returned. Time is returned in Unix timestamp
Example 1 The code is as follows:Copy code $ Test = '2014 372115,850965403 ';$ R = explode (",", $ test );For ($ I = 0; $ I {Echo $ I. ".". $ r [$ I]. "";}?> Output: 0.472347127 1.893372115 2.850965403Example 2 The code is as follows:Copy code
Let's take a look at a simple example. The code is as follows:Copy code Isset ($ a ['key'])Array_key_exists ('key', $ a) array_key_exists It tells you exactly whether a key exists in the array, while isset only returns whether the key value is
_ METHOD _ is a new magic constant after PHP5, indicating the name of the quasi-grammar. The code is as follows:Copy code Class chhua {Function test (){Echo _ METHOD __; }} $ E = new chhua (); $ E-> test (); // output: chhua: test There are
1. Time conversion function in phpStrtotimeThe strtotime () function parses the date and time descriptions of any English text into Unix timestamps.SyntaxStrtotime (time, now)Example The code is as follows:Copy code Strtotime ("today ") DateThe
The code is as follows:Copy code // The Current php loop is 1, and the loop increases sequentially from the inside to the outside. The default break is 1, for example, jumping out of the 2nd-layer loopFor ($ I = 0; $ I Foreach (array (1, 2, 3)
There are three methods to check whether an element is in an array:The in_array 'function searches for the given value in the array. In_array (value, array, type) type is optional. If this parameter is set to true, check whether the data to be
Data Definition The code is as follows:Copy code ......$ Array = array ('one', 'two', 'Three ');Var_dump ($ array );...... In the first line of the code snippet, a one-dimensional array $ array is defined. In the second line, the array is
The code is as follows:Copy code // The "I" after the pattern delimiter indicates a search that is case-insensitive.If (preg_match ("/php/I", "PHP is the web scripting language of choice .")){Print "A match was found .";} Else {Print "A match was
The code is as follows:Copy code Function getTime (){$ Time = "";// Morning time$ H1 = date ("h")> 12? (Date ("h")-12): date ("h ");// Afternoon time$ H2 = (date ("h") + 12)> = 24 )? Date ("h") :( date ("h") + 12 );// Determine whether it is
The code is as follows:Copy code $ ImgPath = "Image address ";// Obtain image information $ imgPath can be a remote addressList ($ srcWidth, $ srcHeight, $ type) = getimagesize ($ imgPath );...Switch ($ type ){Case 1: $ imgCreate =
The code is as follows:Copy code Class getValues {Public function inputValue ($ inputArray ){$ This-> inputArray = $ inputArray; }Public function getValue ($ number ){$ This-> number = $ number;For ($ I = 0; $ I number; $ I ++ ){$ Index =
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