You are here: Re: building an array of files « PHP Programming Language « IT news, forums, messages
Re: building an array of files

Posted by ZeldorBlat on 03/26/07 20:08

On Mar 26, 3:48 pm, lawp...@gmail.com wrote:
> Hello folks -
>
> I'm working on a function to map a php project that's gotten a little
> unwieldly. I'd like to have a reference of all files like the output
> of the unix tree command, like this:
> .
> |-- index.php
> | |-- menu.php
> | |-- content.php
> | |-- admin_page.php
> | | |-- admin_function1.php.inc
> | | |-- admin_function2.php.inc
> | | |-- admin_function3.php.inc
> | | `-- admin_subpage.php
> | | |-- admin_subfunction1.php.inc
> | | |-- admin_subfunction1.php.inc
> | | `-- admin_subfunction1.php.inc
> | `-- user_page.php
> | |-- user_function1.php.inc
> | |-- user_function2.php.inc
> | |-- user_function3.php.inc
> | `-- user_subpage.php
> | |-- user_subfunction1.php.inc
> | |-- user_subfunction1.php.inc
> | `-- user_subfunction1.php.inc
> |
> |-- orphan_page.php
> `-- deprecated_page.php
>
> I have a function that can create such text output ( or close enough )
> from an array structure 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.php
> [5] => ./weekly_report.php
> [6] => ./monthly_report.php
> [7] => ./catalog.php
> [8] => Array (
> [0] => ./login_function.inc
> [1] => ./catalog_item_add.php
> [2] => ./catalog_item_remove.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.php
> [2] => ./invoice_new.php
> [3] => ./invoice_edit.php
> [4] => ./invoice_print.php
> [5] => ./invoice_email.php
> )
> )
> [2] => ./clients_old.php
> [3] => ./old_inventory.php
>
> However, now I'm having a problem building the array of files!
>
> Starting with a default root file, index.php, I can loop through each
> file and find each .php or .inc file. Then I can create an array like
>
> Array (
> [0] => ./index.php
> [1] => Array (
> [0] => ./clients.php
> [2] => ./inventory.php
> [4] => ./daily_report.php
> [5] => ./weekly_report.php
> [6] => ./monthly_report.php
> [7] => ./catalog.php
> [9] => ./orders.php
> [11] => ./invoices.php
> [2] => ./clients_old.php
> [3] => ./old_inventory.php
> )
>
> Then, I need to go through each element and find out what files are
> referenced in that file, and insert that array. So I would get:
>
> Array (
> [0] => ./index.php
> [1] => Array (
> [0] => ./clients.php
> [1] => Array (
> [0] => ./login_function.inc
> [1] => ./client.php
>
> However, I'm having problems getting started. What function can I use
> to insert an array at a certain point?

There isn't really a straightforward way to insert an element at some
arbitrary position in an array. You can split the array in two and
then stitch it back together with something in the middle.

Instead of processing your files level by level, why not do it
recursively? For instance, when your parse index.php, instead of
adding clients.php, then inventory.php, and then going back and
checking for their includes, add clients.php and check for his
includes. When that's done, add inventory.php and check for his
includes. That way you never need to insert the new array in the
middle of the parent -- it'll just happen in the right order the first
time.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация