array mostrar php code example

Example 1: print array php

<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
echo "<pre>";
print_r ($a);
echo "</pre>";
?>
  
Output:

Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )
)

Example 2: dsiplay array on php

$array = array(
	1 => 'apple',
  	2 => 'banana',
)

// Method 1
echo "<pre>";
print_r($array);
echo "</pre>";

// Method 2 
echo "<pre>";
var_dump($array);
echo "</pre>";

// Method 3 (cakephp)
pr ($array);

Tags:

Php Example