This forum is now read-only. Please use our new forums at

For Loops in PHP Forum

View Course » View Exercise

649 points
Submitted by
Robert Kristian Kjell Alm
about 5 years ago

1.5 loops + Arrays general questions about the syntax.

Hello everyone, and i apologize for my english.
in the following code bellow from the exercise i point out two things that i really need a small explaination:

    <link rel="stylesheet" href="stylesheet.css" />
    <title>Codecademy Languages</title>
    <h1>Languages you can learn on Codecademy:</h1>
    <div class="wrapper">
          $langs = array("JavaScript",
          "HTML/CSS", "PHP",
          "Python", "Ruby");

          foreach ($langs as $lang) {
              echo "<li>$lang</li>";



  1. what about the unset($lang) in the end of the Php code?

  2. How we echo the this numbers in the screen? (i ask because i notice that is an UL list tag, and we dont have any counter in our echo statement).

Thank you for your time :)

5 votes


As far as I understand (but I'm by no means a PHP expert) the unset doesn’t do any difference in this particular example. See this SO thread.

About the numbers: the <li> items are numbered by the stylesheet (read the stylesheet.css in the exercise):

ul {
  list-style-type: decimal-leading-zero;

This is a good example of bad, non-semantic HTML. Sure, you can number an <ul> with CSS, but an <ul> is for unordered or unnumbered lists (see specification), and that’s why you really should use <ol> (ordered list) instead if you’re gonna number them.

One of the many reasons the unsemantic approach is a bad idea is accessibility. Blind or sight-impaired people use screen readers (text-to-speech software), which will read the numbers aloud to you if it’s an <ol>, but probably not if it’s a styled <ul> – CSS is largely for the ones who can see.

3117 points
Submitted by
Alex J
about 5 years ago


598dbeaf23cd53c3b8000372_562223586 Robert Kristian Kjell Alm about 5 years ago

It makes sence now. Thank you. :)

5110136bf758055ae9000c0e_634330561 AJ almost 5 years ago

Thanks for your reply Alex J. I am not clear if unset is not necessary then why it is used in the exercise. There should be clear justification for using any JS Terms. The course creator should have explained it.

Picture Alex J over 4 years ago

PHP, not JS, but otherwise I agree with you :)

0 votes


unset, deletes $lang variable.

If you print $lang before unset, it exists and print Ruby.
If you print after unset... the program said you 'that variable is undefined'

foreach sentence, reads each element of the array.


for( $a = 0; $a < $myArrayLength; $a++){
    echo $myArray[$a];

538 points
Submitted by
over 4 years ago