How to structurally display a multi-dimensional array in PHP?

Posted by Jaime Cross on Stack Overflow See other posts from Stack Overflow or by Jaime Cross
Published on 2011-06-29T07:17:02Z Indexed on 2011/06/29 8:22 UTC
Read the original article Hit count: 326

How can I display the contents of an array as follows:

 Company Name
  - Username1
  - Username2
 Another Company Name
  - Username3

The array I have created is as follows:

$array[1]['company_id'] = '12';
$array[1]['company_name'] = 'ABC Company';
$array[1]['company_type'] = 'default';
$array[1]['user_id'] = '23';
$array[1]['user_name'] = 'Andrew';

$array[2]['company_id'] = '12';
$array[2]['company_name'] = 'ABC Company';
$array[2]['company_type'] = 'default';
$array[2]['user_id'] = '27';
$array[2]['user_name'] = 'Jeffrey';

$array[3]['company_id'] = '1';
$array[3]['company_name'] = 'Some Company';
$array[3]['company_type'] = 'default';
$array[3]['user_id'] = '29';
$array[3]['user_name'] = 'William';

$array[4]['company_id'] = '51';
$array[4]['company_name'] = 'My Company';
$array[4]['company_type'] = 'default';
$array[4]['user_id'] = '20';
$array[4]['user_name'] = 'Jaime';

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays