Array display problems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Oct 25, 2012 2:12 am

Array display problems

Postby zmk » Thu Oct 25, 2012 2:18 am


I have a problem go on a two dimensional array. The code I wrote is as follows:

Code: Select all

for ($row = 2; $row < sizeof($data); $row++)
        for($col = 0; $col < sizeof($data[$row]); $col++)
            echo $data[$row][$col];
        echo "<br>";

And appear blanks, but if I change to:

Code: Select all

echo $data;

This Array writes the number of times the existing $ data. Someone can help me to show me the information in this array?

User avatar
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Array display problems

Postby egami » Thu Oct 25, 2012 7:57 am

before you do any of that..
make sure that the array looks like you want it to look...

echo '<pre>'; print_r($data); echo '</pre>';

New php-forum User
New php-forum User
Posts: 20
Joined: Fri Oct 19, 2012 4:32 am
Location: India

Re: Array display problems

Postby jinijames » Mon Oct 29, 2012 3:23 am

$list = array();
$cat = array();
$query = mysqli_query($dbc,"SELECT id, parent_id, category FROM categories ORDER BY parent_id, category LIKE category ASC");
while($row = mysqli_fetch_assoc($query)){
$list[$row['id']] = array_merge($row, array('children' => array()));

foreach($list as $nodeId => &$node) {
if(!$node['parent_id'] || !array_key_exists($node['parent_id'], $list)){
$cat[] = &$node;
} else {
$list[$node['parent_id']]['children'][] = &$node;


hire php developer | hire magento developer

Return to “PHP coding => General”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 5 guests