でforeachループで配列の最後の要素を表示するには、どのように配列に学生の試験の点数を持っている学生は、私が表示されますどのようにのみファーストとPHP
のために選択したときのみ、最初と最後の試験のスコアを表示したいですPHPでforeachループを持つ配列の最初と最後の要素のみ。
これまでのところ、私は私のために動作し、以下の方法を行っているが、最後の要素を表示するには、アレイ
echo $array[0];//in case of numeric array
echo reset($array);// in case of associative array
の最初の要素を表示するには
$y = 0;
$student_total_sessions = $total_counter = sizeof($student_exam_session_data);
if($this->data['show_sessions'] != 'all_sessions')
{
$student_total_sessions = ($student_total_sessions > 2) ? 2 : $student_total_sessions;
}
foreach ($student_exam_session_data as $student_session_id => $student_session_data)
{
$y++;
// only show first and last in case show sessions is pre and post
if($this->data['show_sessions'] != 'all_sessions' && $y > 1 && $y != $total_counter)
{
continue;
}
else
{
echo $student_session_data['exam_score'];
}
}
'array_shift'、' –
array_pop' current'と 'end'機能 –
は'(リセット '試してみてください)'と 'エンド()私はarray_shiftを使用してforeachの前に私の配列を交換したu_mulder' –