Hello!
I am working on a map of a rather large php project that I've been
working on. I hope to create a map of the files of the project that
would look like the output of the unix 'tree' command:
..
|-- index.php
| |-- menu.php
| |-- content.php
| |-- admin_page.php
| | |-- admin_function1 .php.inc
| | |-- admin_function2 .php.inc
| | |-- admin_function3 .php.inc
| | `-- admin_subpage.p hp
| | |-- admin_subfuncti on1.php.inc
| | |-- admin_subfuncti on1.php.inc
| | `-- admin_subfuncti on1.php.inc
| `-- user_page.php
| |-- user_function1. php.inc
| |-- user_function2. php.inc
| |-- user_function3. php.inc
| `-- user_subpage.ph p
| |-- user_subfunctio n1.php.inc
| |-- user_subfunctio n1.php.inc
| `-- user_subfunctio n1.php.inc
|
|-- orphan_page.php
`-- deprecated_page .php
I can scan my php files and pull out references to php file names.
I've created an array that looks like this:
Array
(
[0] =./index.php
[1] =Array
(
[0] =./clients.php
[1] =Array
(
[0] =./login_function. inc
[1] =./client.php
[2] =./client_new.php
[3] =./client_edit.php
)
[2] =./inventory.php
[3] =Array
(
[0] =./login_function. inc
[1] =./inventory_item_ add.php
[2] =./inventory_item_ remove.php
)
[4] =./daily_report.ph p
[5] =./weekly_report.p hp
[6] =./monthly_report. php
[7] =./catalog.php
[8] =Array
(
[0] =./login_function. inc
[1] =./catalog_item_ad d.php
[2] =./catalog_item_re move.php
)
[9] =./orders.php
[10] =Array
(
[0] =./login_function. inc
[1] =./view_order.php
[2] =./order_new.php
[3] =./order_edit.php
)
[11] =./invoices.php
[12] =Array
(
[0] =./login_function. inc
[1] =./view_invoice.ph p
[2] =./invoice_new.php
[3] =./invoice_edit.ph p
[4] =./invoice_print.p hp
[5] =./invoice_email.p hp
)
)
[2] =./clients_old.php
[3] =./old_inventory.p hp
)
However, I'm having problems with the function that reads the array
and outputs the tree-like results. This is what I'm getting:
- ./index.php
- - ./clients.php
- - - ./login_function. inc
- - - ./client.php
- - - ./client_new.php
- - - ./client_edit.php
- - - ./inventory.php
- - - - ./login_function. inc
- - - - ./inventory_item_ add.php
- - - - ./inventory_item_ remove.php
- - - - ./daily_report.ph p
- - - - ./weekly_report.p hp
- - - - ./monthly_report. php
- - - - ./catalog.php
- - - - - ./login_function. inc
- - - - - ./catalog_item_ad d.php
- - - - - ./catalog_item_re move.php
- - - - - ./orders.php
- - - - - - ./login_function. inc
- - - - - - ./view_order.php
- - - - - - ./order_new.php
- - - - - - ./order_edit.php
- - - - - - ./invoices.php
- - - - - - - ./login_function. inc
- - - - - - - ./view_invoice.ph p
- - - - - - - ./invoice_new.php
- - - - - - - ./invoice_edit.ph p
- - - - - - - ./invoice_print.p hp
- - - - - - - ./invoice_email.p hp
- - ./clients_old.php
- - ./old_inventory.p hp
And this is my code:
<?
show_array( $array );
function show_array( $array, $level = 0, $counter = 0 ) {
$count = count($array);
foreach ( $array as $key =$value ) {
if ( is_array($value ) ) {
$level++;
$counter = 0;
show_array( $value, $level, $counter );
} else {
$counter++;
for ( $i = 0; $i <= $level; $i++ ) {
echo " - ";
}
echo "$value\n";
if ( $counter == $count ) {
$level--;
$counter = 0;
}
}
}
}
-------------------
As far as I can tell, the $level counter is not getting decremented
correctly . Can someone help me out?
Steve Lefevre
I am working on a map of a rather large php project that I've been
working on. I hope to create a map of the files of the project that
would look like the output of the unix 'tree' command:
..
|-- index.php
| |-- menu.php
| |-- content.php
| |-- admin_page.php
| | |-- admin_function1 .php.inc
| | |-- admin_function2 .php.inc
| | |-- admin_function3 .php.inc
| | `-- admin_subpage.p hp
| | |-- admin_subfuncti on1.php.inc
| | |-- admin_subfuncti on1.php.inc
| | `-- admin_subfuncti on1.php.inc
| `-- user_page.php
| |-- user_function1. php.inc
| |-- user_function2. php.inc
| |-- user_function3. php.inc
| `-- user_subpage.ph p
| |-- user_subfunctio n1.php.inc
| |-- user_subfunctio n1.php.inc
| `-- user_subfunctio n1.php.inc
|
|-- orphan_page.php
`-- deprecated_page .php
I can scan my php files and pull out references to php file names.
I've created an array that looks like this:
Array
(
[0] =./index.php
[1] =Array
(
[0] =./clients.php
[1] =Array
(
[0] =./login_function. inc
[1] =./client.php
[2] =./client_new.php
[3] =./client_edit.php
)
[2] =./inventory.php
[3] =Array
(
[0] =./login_function. inc
[1] =./inventory_item_ add.php
[2] =./inventory_item_ remove.php
)
[4] =./daily_report.ph p
[5] =./weekly_report.p hp
[6] =./monthly_report. php
[7] =./catalog.php
[8] =Array
(
[0] =./login_function. inc
[1] =./catalog_item_ad d.php
[2] =./catalog_item_re move.php
)
[9] =./orders.php
[10] =Array
(
[0] =./login_function. inc
[1] =./view_order.php
[2] =./order_new.php
[3] =./order_edit.php
)
[11] =./invoices.php
[12] =Array
(
[0] =./login_function. inc
[1] =./view_invoice.ph p
[2] =./invoice_new.php
[3] =./invoice_edit.ph p
[4] =./invoice_print.p hp
[5] =./invoice_email.p hp
)
)
[2] =./clients_old.php
[3] =./old_inventory.p hp
)
However, I'm having problems with the function that reads the array
and outputs the tree-like results. This is what I'm getting:
- ./index.php
- - ./clients.php
- - - ./login_function. inc
- - - ./client.php
- - - ./client_new.php
- - - ./client_edit.php
- - - ./inventory.php
- - - - ./login_function. inc
- - - - ./inventory_item_ add.php
- - - - ./inventory_item_ remove.php
- - - - ./daily_report.ph p
- - - - ./weekly_report.p hp
- - - - ./monthly_report. php
- - - - ./catalog.php
- - - - - ./login_function. inc
- - - - - ./catalog_item_ad d.php
- - - - - ./catalog_item_re move.php
- - - - - ./orders.php
- - - - - - ./login_function. inc
- - - - - - ./view_order.php
- - - - - - ./order_new.php
- - - - - - ./order_edit.php
- - - - - - ./invoices.php
- - - - - - - ./login_function. inc
- - - - - - - ./view_invoice.ph p
- - - - - - - ./invoice_new.php
- - - - - - - ./invoice_edit.ph p
- - - - - - - ./invoice_print.p hp
- - - - - - - ./invoice_email.p hp
- - ./clients_old.php
- - ./old_inventory.p hp
And this is my code:
<?
show_array( $array );
function show_array( $array, $level = 0, $counter = 0 ) {
$count = count($array);
foreach ( $array as $key =$value ) {
if ( is_array($value ) ) {
$level++;
$counter = 0;
show_array( $value, $level, $counter );
} else {
$counter++;
for ( $i = 0; $i <= $level; $i++ ) {
echo " - ";
}
echo "$value\n";
if ( $counter == $count ) {
$level--;
$counter = 0;
}
}
}
}
-------------------
As far as I can tell, the $level counter is not getting decremented
correctly . Can someone help me out?
Steve Lefevre
Comment