PHP Learning Notes <一>

Source: Internet
Author: User
Tags array sort

Bloggers used to write PHP for a while, but the overall feeling was to complete a particular function, not too much in-depth syntax, and not familiar with many PHP functions. So, today I will make a summary of these things ~ (not all the writing I will write, will only use the most common, the most concise way)

Array Chapter

Initially read the PHP array, feeling that this is actually far beyond the scope of the array. I feel that PHP arrays have some Vector+map features in C + + STL. Even this is not enough to generalize its function, its built-in function can add or delete elements in the array header, and can add delete elements at the tail. You can determine the unique array elements, the frequency of the occurrences of the array, and the array sort. Even merge arrays, or let the value of one array become the key of another array, or split it. You can also find the intersection, the difference set, or return several random values, or you can "shuffle".
This is completely different from the C++,java I've been exposed to, and the array assumes the majority of PHP data structures. Or is there very little data structure in the language itself?

If you want to see all the functions here.
We start with the most basic, best-fit array feature.
Key is numeric

$state=array(0=>"Alabama",1=>"Alaska",2=>"Wyoming");当然这样也可以$state=array("Alabama","Alaska","Wyoming");

Key is a string

$state=array("English"=>"s","Spanish"=>"p");

Two-dimensional arrays
There are no two-dimensional arrays in PHP, but this can be done.

$ps=array(array(1,2,3),array(4,5,6),array(7,8,9));

Special case: List of applications
I have not seen this usage in any other language.
List (variable 1, variable 2, variable 3) =array (n/a);
This is equivalent to assigning a value to three variables respectively.

Generates an array, populated with predefined values
I don't think it's necessary because the For loop is not more complicated than that.

$die=range(0,6);$even=range(0,20,2);$letters=range("A","F");

Test array
is an array?

bool is_array($state);

Print array
In addition to the For loop, there is a more convenient way to

boolean print_r($state);

Locating array elements

boolean in_array(mixed ,array)

Copyright NOTICE: This article is for bloggers original article, reproduced please indicate the source.

The above describes the PHP learning notes <一> , including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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