【发布时间】:2011-11-30 02:52:54
【问题描述】:
我想计算一个子字符串在数组中出现的次数。这是一个 Drupal 站点,所以我需要使用 PHP 代码
$ar_holding = array('usa-ny-nyc','usa-fl-ftl', 'usa-nj-hb',
'usa-ny-wch', 'usa-ny-li');
我需要能够调用像foo($ar_holding, 'usa-ny-'); 这样的函数并让它从$ar_holding 数组中返回3。我知道in_array() 函数,但它返回字符串第一次出现的索引。我需要该函数来搜索子字符串并返回一个计数。
【问题讨论】: