In: Computer Science
Suppose we have an array as follow: var $fruits =new Array(“banana”, “strawberry”, “papaya”, “melon”); Write a PHP script which will display the list of fruits in the browser as below: • Fruit 1: banana • Fruit 2: strawberry • Fruit 3: papaya
PHP script :
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>PHP Array</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<?php
//declaring PHP array
$fruits=Array("banana", "strawberry", "papaya", "melon");
//using for loop
for($i=0;$i<count($fruits);$i++)
{
//print each array elements
echo "<li>Fruit ".($i+1).":".$fruits[$i]."</li>";
}
?>
</body>
</html>
=======================================
Output :