You can use strstr () and strrchr () functions to find characters in php strings. The structure of the two functions is as follows:Strstr ($ haystack, $ needle)Strrchr ($ haystack, $ needle)// $ Haystack indicates the parent string, and $ needle
In php, the basic process control structures include sequence structure, branch structure, and cyclic structure.Common control statements include:If, if... Else judgment statementSwitch branch statementWhile, do... While loop statementFor loop
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
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
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
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
Form.html The code is as follows:Copy code 3 7 1 15 Then create a program to process the form:Checkbox. php The code is as follows:Copy code $ A = $ _ POST ["s"];Print_r ($ );?> However, the above program is only used to show whether
Note that when json_decode is returned, the object is required.Json_decode ("string", ture); later I found it was not so perfect ..Json_encode will encode Chinese characters. If a large number of Chinese characters are contained, the length exceeds
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 =
Variable rangeThe scope of a variable is the context defined by it (that is, its effective range ). Most PHP variables have only one separate range. This separate range span also contains the files introduced by include and require. For example:
$ A & $ B and (bitwise and)$ A | $ B or (by bit or)$ A ^ $ B Xor (bitwise Xor)~ $ A Not (Not by bit)$ A $ A >>$ B Shift right (right Shift)Details$ A & $ B: Set the bitwise of 1 in both $ a and $ B to 1;Example: 10 & 12 = 810 101012 11001000 8$ A | $
According to the official explanation:1. $ GLOBALS ['var'] is an external global variable. The code is as follows:Copy code $ Var1 = 1;Function test (){Unset ($ GLOBALS ['var1']);} Test ();Echo $ var1;?> 2. global $ var is an external
When $ _ post [''] and $ _ get [''] are used to obtain parameters in the form, the following error occurs: Notice: Undefined index :--------;Server configuration modificationModify the php. ini configuration file, The code is as follows:Copy code
Custom functionsA function is a set of independent program statements to implement a function. After writing a function into a function, you can easily use it as needed. Reasonable use of functions can make our PHP programs more concise and easy to
User-defined functions are also called Udfs. They are not provided by PHP and are created by programmers. because you have created such functions, you can fully control these functions. therefore, a function can be run in the desired way.1. Declare
Array_values () // returns all elements in the arrayArray_walk () // use a custom function to traverse an array.Arsort (); // reserve the relationship between the values of the array subscript for inverted sortingAsort () // reserve the relationship
The code is as follows:Copy code // Obtain the file directory list. This method returns an array.Function getDir ($ dir = ''){$ Dir = empty ($ dir )? Getcwd (): $ dir;$ DirArray [] = NULL;If (false! = ($ Handle = opendir ($ dir ))){$ I = 0;While (
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