PHP While loop with last record?

I am creating a website and I need to to some PHP in my jQuery.

My code is as follows;

notifications.initMenu({
    2:'#chatPage #tabs #2',
    3:'#chatPage #tabs #3',
    4:'#chatPage #tabs #4',
    5:'#chatPage #tabs #5'
});

I want it so that it uses a while loop to echo;

$pageID:'#chatPage #tabs #$pageID',

And then on the last record echo;

$pageID:'#chatPage #tabs #$pageID'

Any ideas? Thanks.


$array = array();
while( ....) {
    $array[] = "n  $pageID:'#chatPage #tabs #$pageID'";
}
echo implode(',', $array);

如果逗号是你问的问题:

for ($i = 2; $i <= 5; $i++) {
    echo "$i:'#chatPage #tabs #$i'" . ($i !== 5 ? "," ? "") . "n";
}
链接地址: http://www.djcxy.com/p/59410.html

上一篇: array()期望参数2是数组,给定的整数

下一篇: PHP while循环与最后的记录?