From the course: Learning the Standard PHP Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Speeding up array access with SplFixedArray - PHP Tutorial
From the course: Learning the Standard PHP Library
Speeding up array access with SplFixedArray
- According to the PHP online documentation, the SplFixedArray class is much faster than an ordinary array. It also uses less memory. But these advantages come at a price as the name suggests the size of the array is a fixed length and it allows only integers within that range as indexes. You can't use it for associative arrays. Although the class has public methods that allow you set, unset, and get elements, there are no methods to sort them. Another restriction that might not be immediately obvious from the documentation, is that SplFixedArray creates an object not an array. As a result, you can't use it with PHP's huge number of array manipulation functions. So, let's take a look at a bit of code. This is fixed_array.php which you can find in the chapter seven folder of the exercise files. It contains an ordinary array called animals. To convert this to an SplFixedArray, you need to use the from array method which is a static method of the SplFixedArray class. So, let's just add a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Doubly linked lists, stacks, and queues3m 10s
-
(Locked)
Sorting XML and JSON with SplDoublyLinkedList8m 26s
-
(Locked)
Using SplStack and SplQueue6m 25s
-
(Locked)
Understanding heaps2m 55s
-
(Locked)
SplMinHeap and SplMaxHeap5m 3s
-
(Locked)
Sorting XML and JSON with SplHeap7m 9s
-
(Locked)
Finding important information with SplPriorityQueue5m 32s
-
(Locked)
Keeping priority items in chronological order4m 23s
-
(Locked)
Speeding up array access with SplFixedArray6m 48s
-
(Locked)
-