Piticha
Analytics Insight Wizard
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
Creating our PHP Array
First, we are going to create a sample PHP array.
Printing the Array
Then, we use print_r() function to view item in our array.
The default display will look something like this:
Prettifying our Array
Finally, we prettify the display of our array by creating a function.
Adding the above code will prettify the display of our array and it will look something like this.
Full Code
Here's the full code.
That ends this tutorial. Happy Coding :)
First, we are going to create a sample PHP array.
- <?php
- //create example array
- $array
=
array
(
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'neovic'
,
- 'lastname'
=>
'devierte'
- )
,
- array
(
- 'id'
=>
'2'
,
- 'firstname'
=>
'gemalyn'
,
- 'lastname'
=>
'cepe'
- )
,
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'julyn'
,
- 'lastname'
=>
'divinagracia'
- )
- )
;
- ?>
Printing the Array
Then, we use print_r() function to view item in our array.
- <?php
- print_r
(
$array
)
;
- ?>
The default display will look something like this:

Prettifying our Array
Finally, we prettify the display of our array by creating a function.
- <?php
- function
prettyPrint(
$array
)
{
- echo
'<pre>'
.
print_r
(
$array
,
true
)
.
'</pre>'
;
- }
- echo
prettyPrint(
$array
)
;
- ?>
Adding the above code will prettify the display of our array and it will look something like this.

Full Code
Here's the full code.
- <?php
- //create example array
- $array
=
array
(
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'neovic'
,
- 'lastname'
=>
'devierte'
- )
,
- array
(
- 'id'
=>
'2'
,
- 'firstname'
=>
'gemalyn'
,
- 'lastname'
=>
'cepe'
- )
,
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'julyn'
,
- 'lastname'
=>
'divinagracia'
- )
- )
;
- //creating prettify function
- function
prettyPrint(
$array
)
{
- echo
'<pre>'
.
print_r
(
$array
,
true
)
.
'</pre>'
;
- }
- //displaying pretty array
- echo
prettyPrint(
$array
)
;
- ?>
That ends this tutorial. Happy Coding :)