Simple and convenient 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:
- php
- $a="abcd";
- print($a[0]." ".$a[1]." ".$a[2]." ".$a[3]." ");
- ?>
Result: a B c d
Method 2:
- php
-
- $http=array("www","helpphp","cn");
-
- print($http[0].".".$http[1].".".$http[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”;
Using the above method, I created an empty array for the variable using the array language structure, and assigned a value for $ My_array in the subsequent statements. in the previous section, we know that, array subscript (index), auto increment 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);
It should be noted that after the array elements are deleted, the index value will retain the original position and the index will not be re-adjusted. you only need to compare the deleted value 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...