$ array = array ('Main', 'Photo Gallery', 120, 'Rustam', 'Services', 'Lesson 12', 'Link'); This array also contains menu items for the web page. Describe the required menu items in HTML lists.

I get this is a homework question, and we typically won't just do someone's homework for them without them showing any effort themselves, but I think this can be a learning opportunity for anyone who sees this.

$array = array ('Main', 'Photo Gallery', 120, 'Rustam', 'Services', 'Lesson 12', 'Link');

I'd like to begin by saying you accidentally had a typo in your code above. There should not be a space between the dollar sign and the word array. The reason is that the variable is $array, as PHP variables are preceded by a dollar sign. Having a space there would introduce a bug.

We now have this comma-delimited array of strings. An array of this type can almost be thought of as a list ... a list of these strings. We can use PHP to take this PHP array and spit it out as an HTML list. There are two types of HTML lists, ordered and unordered. Ordered lists are preceded by numbers (e.g. List Item 1, 2, 3, etc.) and unordered lists are preceded by bullet points. We denote them with the HTML <ol> and <ul> respectively. Let's spit out an unordered list:

echo '<ul>';

Now, let's loop through the array, and spit out each item in the array as an HTML list item. We use double quotes here because single quotes (as we used above) are literal, in that it will echo everything exactly as contained in the single quotes, but double quotes processes variables.

foreach ($array AS $item)
{
    echo "<li>$item</li>";
}

Now let's close our list.

echo '</ul>';

The end. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.