0

我正在从 xml 中获取数据,它有 100 个元素,我的代码:

foreach($sections->children() as $question){
    $xml_data .= 'Section Name: '.$question->section_name.'<br/>';
    $xml_data .= 'Question No.: '.$question->qno.'<br/>';
    if($question->answer == null || $question->answer == ''){
        $question->answer = 'Not attempted';
        $xml_data .= 'Answer: '.$question->answer.'<br/>';
    } else {
        $xml_data .= 'Answer: '.$question->answer.'<br/>';
    }
    $xml_data .= 'Time: '.$question->time.'<br/>';
    if($question->seen == '1'){
        $xml_data .= 'Seen<br/>';
    } else {
        $xml_data .= 'Not Seen<br/>';
    }
    if($question->flag == '1'){
        $xml_data .= 'Flaged<br/>';
    } else {
        $xml_data .= 'Not Flaged<br/>';
    }
}

从上面我得到 100 个问题,但我从上面只显示 25 个问题,我该怎么做?

4

2 回答 2

1
$count = 1;
foreach($sections->children() as $question){

    ...
    ...

    if($count++ == 25){
        break;
    }
}
于 2013-07-06T06:44:13.773 回答
0

像这样做:

$t = 1; $rate=array(1 , 2 ,3 ,4 ,5 ); print_r($rate); foreach($rate as $rt){ echo $rt; if($rt==3){ exit;} $t++; }
于 2013-07-06T06:49:43.203 回答