PHP中遍歷數組的方法有以下幾種:
$myArray = array("apple", "banana", "cherry");
for($i = 0; $i < count($myArray); $i++) {
echo $myArray[$i] . "<br>";
}
$myArray = array("apple", "banana", "cherry");
foreach($myArray as $value) {
echo $value . "<br>";
}
$myArray = array("name" => "John", "age" => 25, "city" => "New York");
while(list($key, $value) = each($myArray)) {
echo $key . " => " . $value . "<br>";
}
$myArray = array("apple", "banana", "cherry");
reset($myArray);
while(list(, $value) = each($myArray)) {
echo $value . "<br>";
}
請注意,以上方法適用于不同類型的數組,你可以根據數組類型和需求選擇合適的遍歷方法。