PHP Print array

Posted on in Categories , , , , last updated August 25, 2008

Q. How do I print array with PHP?

A. You can easily print an array with php using print_r() function. It orints human-readable information about a variable including array.

<?php
  $distro = array ('r' => 'RedHat', 'd' => 'Debian', 'c' => 'CentOS ');
  print_r ($distro);
?>

Sample Output:

Array
(
    [r] => RedHat
    [d] => Debian
    [c] => CentOS 
)

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment