The array in 1.PHP is actually an ordered map, which can be used as arrays, lists, hash lists, dictionaries, collections, stacks, queues, not fixed lengths
2. Multiple cells in the array definition use the same key name, only the last one is used, and the previous is overwritten.
3. If you want a parameter of a function to always be passed by reference, you can precede the argument with a symbol in the function definition &
The 4.PHP reference is an alias, which means that two different variable names point to the same content; By default, objects are passed by reference. But this is not exactly true, when the object is passed as a parameter, returned as a result, or assigned to another variable, and the other variable is not a reference to the original, except that they all keep copies of the same identifier.
<?phpclass sqlist{public $data =array (); Public $length = 0;} Insert Element function Listinsert (& $sqlist, $i, $e) {//Position out of range if ($i <1 && $i > $sqlist->length+1) { return false; }//starting from the insertion position, all subsequent elements are retired one bit if ($i <= $sqlist->length) {//the position to be inserted is not at the tail for ($k = $sqlist->len Gth-1, $k >= $i-1; $k-) {$sqlist->data[$k +1]= $sqlist->data[$k]; }}//new element inserted $sqlist->data[$i -1]= $e; Length plus 1 $sqlist->length++; return true;} Gets the element function getelement ($sqlist, $i,& $e) {if ($sqlist->length==0 | | $i <1 | | $i > $sqlist->length) { return false; } $e = $sqlist->data[$i-1]; return true;} Delete element function Listdelete ($sqlist, $i,& $e) {if ($sqlist->length==0 | | $i <1 | | $i > $sqlist->length) { return false; } $e = $sqlist->data[$i-1]; If it is the last element if ($i! = $sqlist->length) {//The element after the delete position, move forward one for ($k = $i-1; $k <= $sqlis t->length-1; $k + +) {$sqlist->data[$k]= $sqlist->data[$k +1]; }} $sqlist->length--;} Insert Linear table $sqlist=new SqList () Listinsert ($sqlist, 1, "Tau"), Listinsert ($sqlist, 1, "Shihan");//Get element $e= ""; GetElement ($ sqlist,2, $e); Echo $e. " \ n ";//output tau//Delete element Listdelete ($sqlist, 1, $e); Var_dump ($sqlist);
[PHP] Data structures-sequential storage structure of linear tables PHP implementation