當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP Ds\Map skip()用法及代碼示例

Ds \ Map::skip()函數是PHP中的一個內置函數,用於在給定的位置索引處返回該對。

用法:

Ds\Pair public Ds\Map::skip ( int $position )

參數:該函數接受單個參數$position,該參數用於返回從零開始的位置索引。


返回值:它在給定位置返回Ds \ Pair。

以下示例程序旨在說明PHP中的Ds \ Map::skip()函數:

程序1:

<?php  
  
// Declare a new map 
$map = new \Ds\Map(["a" => 1, "b" => 3, "c" => 5]);  
  
print_r($map->skip(1)); 
  
// Declare another new map 
$map = new \Ds\Map(["1" => "Geeks", "2" => "for",  
                                  "3" => "Geeks"]);  
  
print_r($map->skip(2)); 
  
?>
輸出:
Ds\Pair Object
(
    [key] => b
    [value] => 3
)
Ds\Pair Object
(
    [key] => 3
    [value] => Geeks
)

程序2:

<?php  
  
// Declare a new map 
$map = new \Ds\Map(["Geeks1" => "computer",  
 "Geeks2" => "science", "Geeks3" => 5, "Geeks4" => 20]);  
  
print_r($map->skip(0)); 
  
// Declare another new map 
$map = new \Ds\Map(["x" => "A", "y" => "B", "z" => "C"]);  
  
print_r($map->skip(1)); 
  
?>
輸出:
Ds\Pair Object
(
    [key] => Geeks1
    [value] => computer
)
Ds\Pair Object
(
    [key] => y
    [value] => B
)

參考: https://www.php.net/manual/en/ds-map.skip.php



相關用法


注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Ds\Map skip() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。