PHP array is more commonly used, so I studied the PHP array assignment, here to share with you, I hope to be useful.
An array is a set of variables that are stored in the computer's memory, which can be of different types, including integers, Boolean values, strings, and so on. It can be said that an array is a small database in memory, it provides us a quick way to access the data-can save IO or database frequent access in order to improve some performance, so some of the operations on the array is also a lot.
How to create an array in PHP, you can use the following methods:
method to create an array of:
<?php
$a = "ABCD";
Print ($a [0]. " ". $a [1]." ". $a [2]." ". $a [3]." ");
Results: a b c D
Method Two:
<?php
$http =array ("www", "helpphp", "cn");
Print ($http [0]. ".". $http [1]. ".". $http [2]);
? >
Knowledge Description:
1. We can see from the previous example that the array in PHP will default from subscript (index) to mark the position of the variable in the array, which means we can access the array we created using the form of the $ variable name [index].
2. We use the array () language structure to create the data, which, if not explicitly specified subscript in the array, is incremented by default from 0 onwards. The array we created has been saved in memory, but after the data has been used, we have to do some cleanup to keep the memory leak.
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 created an empty array for variables using the array language structure, in the following statement for $my_array assignment, in a section, we know that the array subscript (index), starting from 0 automatically increment, that is, 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 complete a task like this, you can delete an entire array or an element of an array by using the unset () function. As follows:
unset ($My _array[0];
unset ($My _array);
Note that when you delete an array element, the index value retains its original position and does not readjust the index, and you only need to compare the deletion to see the phenomenon. Use Var_dump () Fung to view the more detailed things in the array, as follows:
var_dump ($My _array);
The above is to teach you the PHP array assignment method, I hope to learn some inspiration.