PHP half way home (2)

Source: Internet
Author: User
Tags vars

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

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.