PHP中的Ds \ Map::toArray()函数用于获取通过将Map实例转换为Array生成的数组。结果数组是一个关联数组,其元素的顺序与指定Map实例的顺序相同。
用法:
array public Ds\Map::toArray ( void )
参数:该函数不接受任何参数。
返回值:该函数返回一个包含指定Map实例的所有元素的关联数组。
以下示例程序旨在说明PHP中的Ds \ Map::toArray()函数:
程序1:
// PHP program to illustrate toArray() function
$map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30]);
print_r($map->toArray());
?>
输出:
Array
(
[1] => 10
[2] => 20
[3] => 30
)
程序2:
// PHP program to illustrate toArray() function
$map = new \Ds\Map(["first" => "Geeks", "second" => "for",
"third" => "Geeks"]);
print_r($map->toArray());
?>
输出:
Array
(
[first] => Geeks
[second] => for
[third] => Geeks
)