[PHP] Data structures-sequential storage structure of linear tables PHP implementation

Source: Internet
Author: User

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

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.