NewToJS
NewToJS

Reputation: 2101

echo PHP array to see its properties/values

I'm querying a database through php and trying to store the result as a php array.

But when I echo $results and call the file in my browser, I just see "Array"

How can I see the results/whats inside of the array?

//find data as an associative array
$results = ORM::for_table('table_name')
            ->where('slug', 'slug_name')
            ->where('date', DATE>='2000-01-01')
            ->where('data', DATA)
            ->find_array();

echo $results

Upvotes: 0

Views: 141

Answers (3)

David Petersen
David Petersen

Reputation: 29

the value of an array element can be another array, multidimensional, using the foreach shows each bucket contains the associative buckets slug, date, data

foreach($results as $result) {
 echo $result['slug'], '<br>';
 echo $result['date'], '<br>';
echo $result['data'], '<br>';
}

Upvotes: 0

Dave
Dave

Reputation: 3658

I use the following function to create a more readable dump.

function debug($v) {
    echo '<pre>';
    print_r($v);
    echo '</pre>';
}

Upvotes: 0

DJ&#39;
DJ&#39;

Reputation: 1770

use print_r($results) or var_dump($results)

Better approach to view on the browser would be

echo "<pre>" . print_r($results) . "</pre>";

or

echo "<pre>" . var_dump($results) . "</pre>";

Upvotes: 1

Related Questions