当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP Ds Map count()用法及代码示例



Ds\Map::count() 函数可以返回映射中值的数量。

用法

public int Ds\Map::count()

Ds\Map::count() 函数没有任何参数。

例子1

<?php  
   $map = new \Ds\Map(["1" => "Tutorials", "2" => "Point", "3" => "India"]);  
  
   print_r($map);  
  
   echo "The number of elements present in a map:"; 
   print_r($map->count()); 
?>

例子2

<?php  
   $map = new \Ds\Map(["1" => "10", "2" => "20", "3" => 30, "4" => 40]);  
  
   print_r($map);  
  
   echo "The number of elements present in map:"; 
   print_r($map->count()); 
  
   echo "\n"; 
  
   $map = new \Ds\Map([1 => "TutorialsPoint", 2 => "to", 3 => "Tutorix"]);  
   print_r($map);  
  
   echo "Number of elements present in map:"; 
   print_r($map->count()); 
?>

相关用法


注:本文由纯净天空筛选整理自 PHP - Ds Map count() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。