How to view and debug PHP arrays

in debug, php

Sometimes when coding or debugging in PHP, it’s helpful to see the entire contents of an array. An easy way to do this is with the print_r command. To make it more readable, wrap it in <pre> tags.

For example, to see the contents of associative array $FormData:

<pre><?= print_r($FormData) ?></pre>

You’ll see output like this:

    [CustomerId] => 2
    [Rating] => 5
    [DateOfBirth] => 01/01/1970
    [FirstName] => John
    [LastName] => Smith
    [Address1] => 1 Main St
    [Address2] =>
    [City] => Santa Monica
    [State] => CA
    [PostalCode] => 90201
    [PhoneNumber] =>

Comments on this entry are closed.

{ 1 trackback }

Previous post:

Next post: