我正在尝试创建一个数组,其中的值根据一些变量重复。在这种情况下:$slipszero = "2"
& $slipsone = "1"
,并且这些值可以更改。
这是我现在的代码:
$problist = array();
foreach ($rows as $value) {
if ($value['f_count'] == 0) {
$placeholder = rtrim(str_repeat($value["uid"] . ',', $slipszero), ', ') ;
array_push($problist, $placeholder);
// The above array_push should act just like:
array_push($problist, $value['uid'], $value['uid']);
} elseif ($value['f_count'] == 1) {
$placeholder = rtrim(str_repeat($value["uid"] . ',', $slipsone), ', ') ;
array_push($problist, $placeholder);
} elseif ($value['f_count'] >= 2) {
$problist[] = $value['uid'];
}
}
所以,从这个数组开始:
Array (
[0] => Array ( [uid] => 105 [f_count] => 0 )
[1] => Array ( [uid] => 106 [f_count] => 1 )
[2] => Array ( [uid] => 107 [f_count] => 0 )
[3] => Array ( [uid] => 108 [f_count] => 1 )
[4] => Array ( [uid] => 109 [f_count] => 2 )
)
我想结束这个数组:
array(15) {
[0] => string(3) "105"
[1] => string(3) "105"
[2] => string(3) "106"
[3] => string(3) "107"
[4] => string(3) "107"
[5] => string(3) "108"
[6] => string(3) "109"
}
相反,我得到了这个:
Array (
[0] => 105,105
[1] => 106
[2] => 107,107
[3] => 108
[4] => 109
)
照顾新生儿让我大吃一惊,因为我不知道自己做错了什么。