Output Arrays with print_r() in PHP

Description

The following code shows how to output Arrays with print_r().

Example


<!DOCTYPE html>/*w  ww.j  a  va  2  s  .c  om*/
<html>
  <body>
    <h1>Outputting Arrays with print_r()</h1>
    <?php
    
    $authors = array( "A", "B", "C", "D" );
    
    $myBook = array( "title" => "XML",
                     "author" => "java2s.com",
                     "pubYear" => 2014 );
    
    echo '<h2>$authors:</h2><pre>';
    print_r ( $authors );
    echo '</pre><h2>$myBook:</h2><pre>';
    print_r ( $myBook );
    echo "</pre>";
    
    ?>

  </body>
</html>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone