(Available since version 1.0)
DynamicArray::fromArray — Import a PHP array in a DynamicArray instance
$array
[,
bool
$save_indexes
= true
] )
Import the PHP array array
in a new
SEIDS::Arrays::Dynamic::DynamicArray instance.
array
The array to import.
save_indexes
Try to save the numeric indexes used in the original array.
Returns an instance of SEIDS::Arrays::Dynamic::DynamicArray containing the array content.
Example #1 DynamicArray::fromArray() example
<?php
require 'vendor/autoload.php'; // A PSR-4 or PSR-0 autoloader
use \SEIDS\Arrays\Dynamic\DynamicArray;
$fa = DynamicArray::fromArray(array(1 => 1, 0 => 2, 3 => 3));
foreach($fa as $i => $v) {
echo $i.':';
var_dump($v);
}
echo "\n";
$fa = DynamicArray::fromArray(array(1 => 1, 0 => 2, 3 => 3), false);
foreach($fa as $i => $v) {
echo $i.':';
var_dump($v);
}
?>
The above example will output:
0:int(2) 1:int(1) 2:NULL 3:int(3) 0:int(1) 1:int(2) 2:int(3)