Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to assign values to PHP arrays

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to assign PHP array", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "how to assign PHP array" bar!

One of the methods:

Results: a b c d

Method 2:

Knowledge description: 1. As we can see from the previous example, the array in PHP indicates the position of the variable in the array by default, starting with the subscript (index), that is, we can access the array we created in the form of: $variable name [index]. 2. We use the array () language structure to create data. If the subscript is not clearly specified in the array, the index is incremented from 0 by default. The array we created has been saved in memory, but after the data is used, we have to do some cleaning. To ensure memory leaks, which I believe will be covered in later chapters. Explain PHP array assignment and destruction, if you haven't learned: PHP array, you should learn about it first.

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

$My_array=array (); $My_array [] = "www" $My_array [] = "helpphp"; $My_array [] = "cn"

Using the above method, I created an empty array for the variable using the Array language structure, and assigned a value to $My_array in the following statement. In the previous section, we know that the array subscript (index) is automatically incremented from 0, which means that 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 element in an array to accomplish the above task, simply use the unset () function, which can delete the entire array or an element in the array, as follows:

Unset ($My_array [0]; unset ($My_array)

It is important to note that after deleting the array elements, the index value will retain its original position and will not re-adjust the index, you only need to compare after the deletion to find this phenomenon. Use var_dump () to view more detailed things in the array, as follows:

Var_dump ($My_array); thank you for reading, the above is the content of "how to assign PHP array". After the study of this article, I believe you have a deeper understanding of how to assign values to PHP array, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report