Simple PHP Array Assignment method _php Tutorial

Source: Internet
Author: User
PHP Array is still more commonly used, so I studied the PHP array assignment, here to take out and share with you, hope to be useful to everyone. An array is a set of variables that are stored in the computer's memory, which can be of different types, including integers, booleans, strings, and so on. It can be said that the array is a small database in memory. It provides a quick way for us to access the data-it can save the IO or the frequent access of the database to improve some performance, so there are a lot of things about arrays.

How to create an array in PHP you can create an array using one of the following methods:

Result: a b c D

Method Two:

Knowledge Note: 1. As we can see from the previous example, in PHP, the array defaults from subscript (index) to the position of the variable in the array, that is, we can access the array we created using the name of the $ variable [index]. 2. We use the array () language structure to create the data, which, if no subscript is explicitly specified, increments the index by default from 0 onwards. The array we created has been saved in memory, but after the data is used, we need to clean it up. To ensure a memory leak, it is believed that this will be covered in a later chapter. Explain the PHP array assignment and destroy, if you have not learned: PHP array, you should first to understand.

How do I assign a value to a PHP array? As follows:

$My _array=array (), $My _array[]= "www" $My _array[]= "helpphp"; $My _array[]= "cn"; Using the above method, I have created an empty array for the variable using the array language structure, and in the following statement we will assign a value to $my_array, in a previous section, we know that the array subscript (index), starting from 0 automatically increment, which means the following statement will output helpphp.

Print $My _array[1]; If you want to output $my_array all at once, you can use Print_r ($My _array). How to destroy an array or an array of elements to complete the task above, as long as the unset () function is used, it can delete an entire array or an element of an array, as follows:

Unset ($My _array[0]; unset ($My _array); It is important to note that after you delete an array element, the index value retains its original position and does not re-adjust the index, you only need to be able to find this phenomenon after the deletion. Use Var_dump () to see more detail in the array, as follows:

Var_dump ($My _array);

http://www.bkjia.com/PHPjc/371945.html www.bkjia.com true http://www.bkjia.com/PHPjc/371945.html techarticle PHP Array is still more commonly used, so I studied the PHP array assignment, here to take out and share with you, hope to be useful to everyone. The so-called array is a set of variables to protect ...

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