The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Display Array Contents

Last updated on:
echo '<pre>';
print_r ($_POST);
echo '</pre>';


  1. Mark Cole
    Permalink to comment#

    Seriously? This is terrible lol.

  2. Kenrick
    Permalink to comment#

    lmao!!!!!!!!!!!!!!!!!!!!!!!!! this is funny

  3. Dyllon
    Permalink to comment#


    so, an attempt to correct this users coding..


    $array[0] = "CSS";
    $array[1] = "HTML";
    $array[2] = "PHP";
    $array[3] = "JavaScript";
    echo '';
    print_r ($array);
    echo '';


        [0] => CSS
        [1] => HTML
        [2] => PHP
        [3] => JavaScript
  4. Chris
    Permalink to comment#

    haha this is too basic for a snippet

  5. Bill Brown
    Permalink to comment#

    Or this:

    echo '<pre>',print_r($array,1),'<pre>';

    • Gringer

      For beginners:

      The reason we use a comma instead of a period/dot between the ‘pre’ and the print_r() is because print_r() does an echo from itself.

      If you would use a dot instead then it PHP will echo print_r() and AFTER that a pre and a /pre.


      As we can read here:

      print_r() takes a second argument to return instead of echo:

      echo '<pre>' . print_r($array,true) . '</pre>';

      Note: We use dots instead of comma’s, and give print_r() an extra ‘true’ (= return).

      Not as short, but just to explain to beginners how the spoon fits in the fork xD

  6. superman
    Permalink to comment#

    I’m sorry to say that not everybody is experienced who come here.It is a wonderful resource for the all levels of coder. Keep it up Chris.. Thanks

  7. dekorasyon
    Permalink to comment#

    Gringer. I agree with you. Thanks.

  8. Waterman
    Permalink to comment#

    You can as well use the foreach statement to get the content of an array out.. you use that when you need to perform something to every single one of the array element…

    $someArr = array(1,2,3,4,5…)
    foreach ($someArr as $newVar){
    //whatever you need to do to array members
    echo $newVar;

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed