Functions are essential to every programming language. I have to understand what is the most acute difference between PHP and the return type, note that you must use the corresponding type to receive the return value ~ The old faces in C ++ pass values by reference & quot; & amp; & quot; default parameter recursive function-a powerful tool for drawing forms! Hero... SyntaxHighlighter
Functions are essential to every programming language. I have to understand the differences in PHP.
The most acute is the return type, which does not need to be specified in the function declaration.
The only thing you need to note is that you have to use the corresponding type to receive the return value ~
Old faces in C ++
Pass value by reference "&"
Default parameters
Recursive functions-a powerful tool for drawing forms!
The hero does not ask for the source. the weak type creates an array with souls.
Assignment method:
$ Say = array ("Chinese", "English", "French ");
// Equivalent
$ Say [0] = "Chinese"; $ say [1] = "English"; $ say [2] = "French ";
$ Say = array ("China" => "Chinese", "England" => "English", "France" => "French ");
// Equivalent
$ Say ["China"] = "Chinese ";
$ Say ["England"] = "Chinese ";
$ Say ["France"] = "Chinese ";
The PHP array is different from the java array, which combines the array and map feeling.
$ MyArray = array (0 => "0th", "2" => "2", "all" => "really ");
Echo $ myArray [0]; // Normal mode
Echo $ myArray [1]; // empty calculation for null values
Echo $ myArray [2]; // outputs "2"
Echo $ myArray ["2"]; // It will also output "2"
Echo $ myArray ["This is OK"]; // outputs "this is OK"
Auto-increment index
$ MyArray [] = 0;
$ MyArray [] = 1;
$ MyArray [] = 2;
$ MyArray [] = 3;
Echo $ myArray [3]; // output 3
Powerful list () can extract arrays-involving the matching function javase (). let's talk about it later ~
The Range () function also supports filtering.
$ MyArray = range ("a", "z", 3); // From "a" to "z", output
// Output a d g j m p s v y
Extended Array www.2cto.com
Returns the value of the index:
Print_r ($ myArray );
Determine whether it is an array:
Boolean is_array (mixed var );
Hybrid --- queue + stack --- convenient operations before and after
Array_unshift ($ vars, $ key, $ value); // add from scratch
Array_push ($ vars, $ key, $ value); // add from the end
Array_shift ($ vars); // delete from scratch:
Array_pop ($ vars); // delete from the end:
Array 4-query
Array Q: Are you there?
// For key:
Boolean array_key_exists ($ key, $ vars );
// For value:
Boolean in_array ($ value, $ vars); array: If yes, tell me where you are
$ Key array_search (& value, $ vars); array Q: Can you show me your address book?
$ Keys = array_keys ($ vars); // return key value array
Print_r ($ keys); array Q: Who lives in?
$ Values = array_keys ($ vars); // return key value array
When the index is not a number, I always use for (int I = 0; I ++...
// Return the key's
While ($ key = key ($ vars ))
{
Next ($ vars );
}
// Return the value
While ($ value = current ($ vars ))
{
Next ($ vars );
}
The next () method is good. you can continue to locate it ~
$ Value prev ($ vars) // Previous
$ Value reset ($ vars) // Start Point
$ Value end ($ vars) // You can view the array at the end.
How big is it?
Int count ($ vars) // returns the array size
// Recursive count:
Int count ($ vars, 1); // The second parameter is the number of times that each type appears in the mode selection? Frequency ~
$ Vars_f array_count_values ($ vars); I just want to know how many classes there are! Remove duplicates
$ Vars_u array_unique ($ vars); check it.
Sort by ASCII code from small to large (default, available)
Sort ($ vars); // How does the key value you sorted change in basic sorting?
Asort ($ vars); // does the sorting of key values not change from large to small?
Resort ($ vars) // a1 -- good a10-a2 or good a1-a2-a10? Natural sorting
Natsort ($ vars) should not ignore the aesthetic of sorting because of case sensitivity
Natcasesort ($ vars) cannot only be arranged by content, right? Key sorting
? Ksort ();
It's time for DIY ~
Usort ($ vars, 'myfunction ');
// Return value of myFun (): smaller than-negative, equal to-0, greater than-positive
This array structure does not work. I want to modify it!
Merge:
Array_merge (& vars1, $ vars2); recursive merge:
Array_merge_recursive (& vars1, $ vars2 );
// Recursive operations merge values of the same value into arrays for appending.
Array_combine (& vars1, $ vars2); connection
Array_merge (& vars1, $ vars2); Division 1:
$ Vars_r = array_slice ($ vars, 4); // remove the first four partitions 2:
$ Vars_r = array_slice ($ vars, 2,-2); // remove the first two, and the last two are the original arrays.
Split
$ Vars_r = array_slice ($ vars, 4,-2); original array $ vars, retain the first four
The returned $ vars_r has the last two
Intersection:
$ Vars_r = array_intersect ($ vars1, $ vars2, $ vars3); difference set: first one has, others do not have
$ Vars_r = array_diff ($ vars1, $ vars2, $ vars3); shuffling of array elements ~ :
Shuffle ($ vars); sum
$ Sum = array_sum ($ vars );
From matter605924657