PHP中的Ds /Map::reverse()函數用於就地反轉指定Map實例的元素。也就是說,該函數就地反轉了指定Map實例中存在的元素的順序。
用法:
Ds\Pair public Ds\Map::skip ( int $position )
參數:該函數不接受任何參數。
返回值:該函數不返回任何值。
以下示例程序旨在說明Ds /Map::reverse()函數:
程序1:
<?php
// PHP program to illustrate reverse() function
$map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30]);
// Reverse the Map
$map->reverse();
// Print the revresed Map
print_r($map);
?>輸出:
Ds\Map Object
(
[0] => Ds\Pair Object
(
[key] => 3
[value] => 30
)
[1] => Ds\Pair Object
(
[key] => 2
[value] => 20
)
[2] => Ds\Pair Object
(
[key] => 1
[value] => 10
)
)
程序2:
<?php
// PHP program to illustrate reverse() function
$map = new \Ds\Map(["first" => "Geeks", "second" => "for",
"third" => "Geeks"]);
// Reverse the Map
$map->reverse();
// Print the Map
print_r($map);
?>輸出:
Ds\Map Object
(
[0] => Ds\Pair Object
(
[key] => third
[value] => Geeks
)
[1] => Ds\Pair Object
(
[key] => second
[value] => for
)
[2] => Ds\Pair Object
(
[key] => first
[value] => Geeks
)
)
參考:http://php.net/manual/en/ds-map.reverse.php
相關用法
- PHP Ds\Set reverse()用法及代碼示例
- PHP Ds\Deque reverse()用法及代碼示例
- PHP Ds\Sequence reverse()用法及代碼示例
- PHP Ds\Vector reverse()用法及代碼示例
- PHP each()用法及代碼示例
- PHP dir()用法及代碼示例
- PHP exp()用法及代碼示例
- PHP Ds\Map map()用法及代碼示例
- PHP Ds\Map last()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP cos( )用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 PHP | Ds\Map reverse() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
