Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Cách hiển thị giá trị mảng bằng do-while hoặc for trong PHP

Cú pháp hiển thị giá trị mảng:

do {
    // statement1
    // statement2
    ...
    n
} while(yourCondition);

Ví dụ

<!DOCTYPE html> <html> <body> <?php 
$values = array('John', 'David', 'Mike', 'Sam', 'Carol');
$i = 0;
$len = count($values);
do {
    echo $values[$i], " ";
    $i++;
} while($i < $len);
?> </body> </html>

Kết quả

John David Mike Sam Carol