Skip to main content
CSS-Tricks
  • Articles
  • Videos
  • Almanac
  • Newsletter
  • Guides
  • DigitalOcean
  • DO Community
Search
Code Snippets → PHP → Display Array Contents

Display Array Contents

Avatar of Chris Coyier
Chris Coyier on Aug 21, 2009
echo '<pre>';
print_r ($_POST);
echo '</pre>';
Psst! Create a DigitalOcean account and get $200 in free credit for cloud-based hosting and services.

Comments

  1. Mark Cole
    Permalink to comment# September 4, 2009

    Seriously? This is terrible lol.

    Reply
    • Frank
      Permalink to comment# September 4, 2009

      He wanted that $1 so much. :’)

  2. Kenrick
    Permalink to comment# September 4, 2009

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

    Reply
  3. Dyllon
    Permalink to comment# September 10, 2009

    lollllll

    so, an attempt to correct this users coding..

    input:

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

    output:

    Array
    (
        [0] => CSS
        [1] => HTML
        [2] => PHP
        [3] => JavaScript
    )
    Reply
    • Dyllon
      Permalink to comment# September 10, 2009

      woops, the echo tags have a ‘pre’ tag in them.

  4. Chris
    Permalink to comment# September 22, 2009

    haha this is too basic for a snippet

    Reply
  5. Bill Brown
    Permalink to comment# September 25, 2009

    Or this:


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

    Reply
    • Gringer
      Permalink to comment# May 16, 2010

      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.

      —
      Gringer
      PS:

      As we can read here:
      http://nl3.php.net/manual/function.print-r.php

      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# April 18, 2010

    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

    Reply
  7. dekorasyon
    Permalink to comment# January 23, 2011

    Gringer. I agree with you. Thanks.

    Reply
  8. Waterman
    Permalink to comment# August 24, 2011

    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){
    $newVar*=9;
    //whatever you need to do to array members
    echo $newVar;
    }

    Reply
  9. shaik
    Permalink to comment# January 13, 2016

    Hi iam trying to use this code with an animated login and register form. the form works fine. as soon as i put the php err code the whole form looses its css and freezes. please check code here http://codepen.io/anon/pen/PZKBpW

    thanks your help will be appreciated

    Reply
  10. shaik
    Permalink to comment# January 15, 2016

    hi sorted.
    check the solution here http://codepen.io/anon/pen/XXemJB

    Reply
  11. shaik
    Permalink to comment# January 15, 2016

    there is one problem though . i want my err mesg with a border. if i show border on css then the form displays the border of the div even if there is no err. basically i want the div there as empty and if the submit has errors then the err show and outline with a border. any help there pleae

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CSS-Tricks is powered by DigitalOcean.

Keep up to date on web dev

with our hand-crafted newsletter

DigitalOcean
  • DigitalOcean
  • DigitalOcean Community
  • About DigitalOcean
  • Legal
  • Free Credit Offer
CSS-Tricks
  • Email
  • Guest Writing
  • Book
  • Advertising
Follow
  • Mastodon
  • Twitter
  • Instagram
  • YouTube
  • CodePen
  • iTunes
  • RSS
Back to Top