Php 将数组的每个第100个元素转换为逗号分隔的字符串

Php 将数组的每个第100个元素转换为逗号分隔的字符串,php,arrays,foreach,Php,Arrays,Foreach,我有一个大小不同的数组,可以是1到200000之间的任意数组 我想循环此数组,然后将值保存到逗号分隔的字符串中,如果大小大于100,则将前100个值保存到字符串中,\perform my operation \Com for the next 100 Continue from the next value in the array $users = $this->_db->get('search_results', array('search_token', '=' , $sear

我有一个大小不同的数组,可以是1到200000之间的任意数组

我想循环此数组,然后将值保存到逗号分隔的字符串中,如果大小大于100,则将前100个值保存到字符串中,\perform my operation \Com for the next 100 Continue from the next value in the array

$users = $this->_db->get('search_results', array('search_token', '=' , $search_token) );
$results = $users-> results();
$unique = $users->count();

foreach($results as $result){
  print_r($result->id); //print each id.
}
这是我试图进入字符串的结果的id值,我现在所做的就是打印

我想应该是这样的

$string = "0,1,2,3,5,5.....99";
dosomething($string);
然后循环将字符串更新为“100101102103104……145”


但是我想不出来,我会修改我的建议,看看我能不能想出来。

基本上跟踪一个
$计数器
,并在数组中循环,将数组项连接成一个字符串。当您到达第100个元素时,执行您的操作(在本例中,我只为每个第10个元素添加一个逗号,但想法是相同的)

将给出输出:

abcdefghij,klnmopqrst,
一个简单的
foreach($results as$counter=>$result){if($counter%100)!==0){echo',';}echo$result->id;}
将允许您测试每个第100个元素
abcdefghij,klnmopqrst,