Simple PHP array assignment method-PHP Tutorial-php Tutorial

Source: Internet
Author: User
Simple PHP array assignment method. PHP arrays are still commonly used. so I studied the assignment of PHP arrays and shared them here. I hope they will be useful to you. The so-called array is a set of variables that are usually used to preserve the PHP array. so I have studied the PHP array assignment. here I will share it with you and hope it will be useful to you. An array is a set of variables stored in computer memory. These variables can be of different types, including integers, boolean values, and strings. array is a small database in memory. it provides a quick way for us to access data-it can save the IO or frequent access to the database to improve some performance, so there are many operations on the array.

You can use one of the following methods to create an array in PHP:

Result: a B c d

Method 2:

Knowledge description: 1. we can see from the previous example that, by default, the array in PHP marks the position of the variable in the array starting from the subscript (index), that is, we can use: $ access the created array using the variable name [index. 2. we use the array () language structure to create data. If no subscript is specified in the array, the index is incremented from 0 by default. the array we created has been saved in the memory, but after using the data, we need to clear it. To ensure memory leakage, I believe this will be involved in subsequent chapters. Description: PHP array assignment and destruction. if you haven't learned: PHP array, you should first learn about it.

How to assign values to PHP arrays? As follows:

$ My_array = array (); $ My_array [] = "www" $ My_array [] = "helpphp"; $ My_array [] = "cn"; through the above method, I created an empty array for the variable using the array structure, and assigned a value for $ My_array in the following statement. in the previous section, we know that the array subscript (index ), auto increment starts from 0, that is, the following statement will output helpphp.

Print $ My_array [1]; if you want to output $ My_array at a time, you can use print_r ($ My_array ). to complete the preceding task, you only need to use the unset () function to destroy the elements in an array or array, as shown in the following code:

Unset ($ My_array [0]; unset ($ My_array); note that after deleting an array element, the index value retains its original position and does not re-adjust the index, you only need to delete and compare to find this phenomenon. You can use var_dump () to view more details in the array, as shown below:

Var_dump ($ My_array );

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