Jump to content

m.jay.victor

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Posts posted by m.jay.victor

  1. Thank you Abra, I was however trying to extend my knowledge of foreach, and how I may nest arrays. Your way is by far functionally better of course, but I am just trying to extend what I got from that one lesson.

     

    You did however teach me that it was possible to merge arrays though:)

    Wich brings me to...

    $artists = array_merge($artists, $morebands);

    Would that have not been simpler?

  2. to learn how.

    I started learning PHP about 2 days ago and I am following that tutorial I linked earlier. The next logical step for me was to see if I could nest the arrays.

     

    Anyhow, I noticed part of what you fixed was the way I defined the artist array.

    from

    $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands");

    to

    $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', $morebands);

     

    What i don't understand is why this was necessary. I know it was, because the code would output the word "array" on the last line if you did not remove the quotes.  Can you explain why this happened though?

  3. <html>

    <head></head>

    <body>

    My favourite bands are:

    <ul>

     

    <?php

     

    // define arrays

    $morebands = array('Desturbed', 'Anthrax');

    $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands");

    // loop over it

    // print array elements

    foreach ($artists as $a) {

        if ($a != 'Array'){

      echo '<li>'.$a;

    }

      Else {

    foreach ("${$a}" as $b){

    echo '<li>'.$b;

    }

    }

    }

     

    ?>

     

    </ul>

    </body>

    </html>

     

    I can not figure out why this will not work:(

    I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well.

     

    I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so).

     

    right now I am working on

    http://devzone.zend.com/node/view/id/635

     

    anyhow thanks for any help!

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.