在foreach php中,从100个数据中仅获取25个数据
我从xml中获取数据,其中包含100个元素,我的代码:在foreach php中,从100个数据中仅获取25个数据,php,foreach,Php,Foreach,我从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 ==
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/>';
}
}
foreach($sections->children()作为$question){
$xml_data.='Section Name:'。$question->Section_Name.
;
$xml_data.='Question No.:'.$Question->qno.
;
如果($question->answer==null | |$question->answer==''){
$question->answer='未尝试';
$xml_data.='Answer:'.$question->Answer.
;
}否则{
$xml_data.='Answer:'.$question->Answer.
;
}
$xml_data.='Time:'.$question->Time.
;
如果($question->seen==“1”){
$xml_data.='Seen
;
}否则{
$xml_data.=“未看到
”;
}
如果($question->flag==“1”){
$xml_data.='flagid
;
}否则{
$xml_data.=“未加鞭毛
”;
}
}
从上面我得到了100个问题,但我想从上面只显示25个,我应该怎么做?这样做:
$count = 1;
foreach($sections->children() as $question){
...
...
if($count++ == 25){
break;
}
}
$t = 1; $rate=array(1 , 2 ,3 ,4 ,5 ); print_r($rate); foreach($rate as $rt){ echo $rt; if($rt==3){ exit;} $t++; }
我认为这是行不通的<代码>$t25