Home >Backend Development >PHP Problem >What is the difference between php array and linked list

What is the difference between php array and linked list

王林
王林forward
2020-01-25 21:03:033092browse

What is the difference between php array and linked list

The difference between php arrays and linked lists can be seen from the following two aspects:

1. From the perspective of logical structure

1. Arrays must Defining a fixed length (number of elements) in advance cannot adapt to the dynamic increase or decrease of data. When the data increases, the number of elements may exceed the originally defined number; when the data decreases, memory waste occurs; the array can be directly accessed according to the subscript.

Related free learning video tutorial sharing: php video tutorial

2. The linked list dynamically performs storage allocation, which can adapt to the dynamic increase and decrease of data. And you can easily insert and delete data items. (When inserting or deleting data items in the array, other data items need to be moved, which is very cumbersome.) The linked list must find the next element based on the next pointer.

2. From the perspective of memory storage

1. (static) arrays allocate space from the stack, which is convenient and fast for programmers, but the degree of freedom is small.

2. The linked list allocates space from the heap, which has a large degree of freedom but is more troublesome to apply for and manage.

It can be seen from the above comparison that if you need to access data quickly and rarely or without inserting and deleting elements, you should use an array; on the contrary, if you need to frequently insert and delete elements, you need to use a linked list data structure. .

Recommended related articles and tutorials: php tutorial

The above is the detailed content of What is the difference between php array and linked list. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete