Converting a SplFixedArray to a PHP array

We might also need to convert a SplFixedArray to a regular PHP array to apply some predefined array functions from PHP. Like the previous example, this is also a very simple thing to do:

$items = 5; 
$array = new SplFixedArray($items);
for ($i = 0; $i < $items; $i++) {
$array[$i] = $i * 10;
}

$newArray = $array->toArray();
print_r($newArray);

This will produce the following output:

Array 
(
[0] => 0
[1] => 10
[2] => 20
[3] => 30
[4] => 40
)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset