User Tools

Site Tools


uphp:functions:print_r

print_r

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Dump the contents of an array to the current output

Description

print_r ( array $array )

Prints human-readable information about an array

Parameter

$array: The array to dump to the current output

Return Values

None

Examples

Create an array with key/value pairs and dump the contents to the current output

<pre><?
  $arr=array();
  $arr['name']="John";
  $arr['age']=30;
  $arr['status']=1;
  print_r($arr);
?></pre>

The above example will output:

[$arr] = Array (
(string) [name] => John
(int) [age] => 30
(int) [status] => 1
) 

Dump some different types of arrays

<pre><?
  $arr1=array(); // create a blank array
  $arr1[0]='Item 1';
  $arr1[]='Item 2'; // automatically appends the value to the next available key
  $arr1[2]='Item 3';
  print_r($arr1);
 
  print("\r\n\r\n\r\n");
 
  $arr2=array(1, 2.5, 3.7, 4); // array of numbers
  print_r($arr2);
 
  print("\r\n\r\n\r\n");
 
  $arr3=array("one", 2, 3.5, $arr2); // mixed array
  print_r($arr3);
?></pre>

The above example will output:

[$arr1] = Array (
(string) [0] => Item 1
(string) [1] => Item 2
(string) [2] => Item 3
) 


[$arr2] = Array (
(int) [0] => 1
(float) [1] => 2.500000
(float) [2] => 3.700000
(int) [3] => 4
) 


[$arr3] = Array (
(string) [0] => one
(int) [1] => 2
(float) [2] => 3.500000
[$arr2] = Array (
    (int) [0] => 1
    (float) [1] => 2.500000
    (float) [2] => 3.700000
    (int) [3] => 4
)
) 

Note

Although this function has other uses, it is most commonly used as a tool for testing and debugging new scripts.

See Also

array() - Create an array, with optional values

array_key() - Return the key for an array index

array_keys() - Return keys for an array that has key/value pairs

explode() - Turn a string into an array

implode() - Turn an array into a string

indexed_array() - Create an array of a specific type and size

is_array() - Check if a variable is an array

json_encode() - JSON encode an array into a string, with optional method

sizeof() - Return the number of elements in an array

uPHP Variable Types and Limits

uphp/functions/print_r.txt · Last modified: 2021/09/13 05:57 (external edit)