PHP Halfway decent (2) _php tutorial

Source: Internet
Author: User
Functions are essential for every programming language, and I need to understand how PHP is different
The most sharp is the return type, which is not indicated in the function declaration
The only thing to note is that you have to receive the return value with the corresponding type ~
The old face in C + +

Pass Value by reference "&"
Default parameters
Recursive function---a sharp weapon to draw a form!

The hero does not ask the source, the weak type is created by the soul of the array

How to assign a value:

$say = Array ("Chinese", "中文版", "French");
Equivalent
$say [0] = "Chinese"; $say [1] = "中文版"; $say [2] = "French";


$say = Array ("China" = "Chinese", "England" = "Chinese", "France" and "French");

Equivalent

$say ["China"] = "Chinese";

$say ["England"] = "Chinese";

$say ["France"] = "Chinese";

The PHP array is different from the Java array, which is a synthesis of the array and map of the feeling

$myArray = Array (0=> "No. 0", "2" = "2", "This is OK" and "this really can");

echo $myArray [0]; Normal mode

echo $myArray [1]; An empty count with no value

Echo $myArray [2]; Will output "2."

Echo $myArray ["2"]; It will also output "2."

echo $myArray ["This Is all right"]; Will output "This really can"

Index Auto Increment

$myArray [] = 0;

$myArray [] = 1;

$myArray [] = 2;

$myArray [] = 3;

Echo $myArray [3]; Will output 3

The powerful list () can extract the array---involves matching function explore (), and then again ~

The Range () function also has a filtering effect
$myArray = Range ("A", "Z", 3); From "a" to "Z", each of the 3 output one

Output a D G J M P S v y

Array expansion www.2cto.com
Returns the value corresponding to the index:
Print_r ($myArray);

To determine whether an array is a group:
Boolean Is_array (mixed Var);

Mixed---queue + stack---easy to operate before and after

Array_unshift ($vars, $key, $value); Add from scratch

Array_push ($vars, $key, $value); From the tail plus

Array_shift ($vars); Delete from scratch:

Array_pop ($vars); Delete from tail:

Array four Ask---query
Array Q: Are you there?
For key:
Boolean array_key_exists ($key, $vars);
For value:
Boolean In_array ($value, $vars); array Q: If you're here, tell me where you are.
$key Array_search (&value, $vars); array Q: Let me see your address book.
$keys = Array_keys ($vars); Returns an array of key values

Print_r ($keys); array Q: Who lives?
$values = Array_keys ($vars); Returns an array of key values

When the index is not a number, I always use the for (int i=0;; i++) laid off ...

Returns the key
while ($key =key ($vars))
{
Next ($vars);
}
Returns the value of the
while ($value =current ($vars))
{
Next ($vars);
}
The next () method is good, you can continue to locate ~
$value prev ($vars)//Previous

$value Reset ($vars)//starting point

$value End ($vars)//End-point full view array
How big is the total?
Int count ($vars)//return array size
Recursive count:
Int count ($vars, 1); The second parameter is how many times each type of pattern selection occurs? Frequency ~
$vars _f array_count_values ($vars); I just want to know how many kinds! Remove duplicates
$vars _u Array_unique ($vars); Tidy up and look at
From small to large in ASCII code order (default, you can choose)
Sort ($vars); Basic sort the key values you've lined up have changed.
Asort ($vars); The key value does not change the sort from big to small can you only look back?
Resort ($vars)//a1--a10-a2 good, or a1-a2-a10 good? Natural sort
Natsort ($vars) do not ignore sorting aesthetics because of capitalization
Natcasesort ($vars) don't just sort by content? Key sort
? Ksort ();

It's time to DIY.
Usort ($vars, ' myFunction ');
Return of Myfun (): Less than-negative, equal to-0, greater than-positive

This array structure does not work, I want to change!
Merge:
Array_merge (&vars1, $vars 2); recursive merging:
Array_merge_recursive (&vars1, $vars 2);
Recursion will append the same value as the combined array of values
Array_combine (&vars1, $vars 2); connection
Array_merge (&vars1, $vars 2); Division 1:
$vars _r = Array_slice ($vars, 4);//Remove the first four divisions 2:
$vars _r = Array_slice ($vars, 2,-2);//Remove the first 2, and the first 2 to divide the original array unchanged

Split
$vars _r = Array_slice ($vars, 4,-2); Original array $vars, preserving the first 4

The returned $vars_r has the following 2

Intersection:
$vars _r = Array_intersect ($vars 1, $vars 2, $vars 3); difference set: First one, others not.
$vars _r = Array_diff ($vars 1, $vars 2, $vars 3); Shuffle of array elements ~:
Shuffle ($vars); sum
$sum = Array_sum ($vars);


Excerpted from matter605924657

http://www.bkjia.com/PHPjc/478243.html www.bkjia.com true http://www.bkjia.com/PHPjc/478243.html techarticle function is necessary for every programming language, I have to understand what is the difference between PHP is the most sharp is the return type, not in the function declaration note that the only thing you have to pay attention to is that you have to use the corresponding type ...

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