> I have a multi-dimensional array. Looks like this:
>
> $work_order_hdr = array ('whdr_id'=>'record_no',
>                          'whdr_order_no'=>'request_no',
>                          'whdr_site_id'=>'site_id',
>                          'whdr_user_id'=>'user_id',
>                          'whdr_location'=>'location',
>                          'whdr_date_submitted'=>'date_submitted',
>                          'whdr_date_acknowledged'=>'date_acknowledged',
>                          'whdr_date_approved'=>'date_approved',
>                          'whdr_date_rejected'=>'date_rejected',
>                          'whdr_date_cancelled'=>'date_cancelled',
>                          'whdr_date_closed'=>'date_closed',
>                          'whdr_status'=>'status');
>
> $work_order_hdr['links']['whdr_site_id']='site_master["site_id"]';
> $work_order_hdr['links']['whdr_user_id']='user_master["user_id"]';
>
> I use the a part of the array to display the field names from the db in a
more
> user-friendly manner.  The 'links' part is new and is intended to link
certain
> fields to fields in other tables.
>
> I have a variable called '$tbl' that contains a table name, in this case
> $tbl='work_order_hdr'. I can reference 'whdr_id' like this:
>
> echo $$tbl['whdr_id']
>
> That gives the expected 'record_no'
>
> I can't seem to access the links correctly. I've tried various
combinations of
> 'isset' and 'array_key_exists' but can't find the correct syntax.

Wouldn't it be:

echo ${$tbl['links']['whdr_site_id']};
echo ${$tbl['links']['whdr_user_id']};

You know you could move your array down one more dimension and do away with
the variable variables...

$ar = array('work_order_hdr' =>
               array ('whdr_id'=>'record_no',
                         'whdr_order_no'=>'request_no',
                         'whdr_site_id'=>'site_id',
                         'whdr_user_id'=>'user_id',
                         'whdr_location'=>'location',
                         'whdr_date_submitted'=>'date_submitted',
                         'whdr_date_acknowledged'=>'date_acknowledged',
                         'whdr_date_approved'=>'date_approved',
                         'whdr_date_rejected'=>'date_rejected',
                         'whdr_date_cancelled'=>'date_cancelled',
                         'whdr_date_closed'=>'date_closed',
                         'whdr_status'=>'status'));

$ar['work_order_hdr']['links']['whdr_site_id']='site_master["site_id"]';
$ar['work_order_hdr']['links']['whdr_user_id']='user_master["user_id"]';

Then, if you have $tbl = 'work_order_hdr', you use

echo $ar[$tbl]['wdhr_id'];

echo $ar[$tbl]['links']['whdr_site_id'];

etc... Pretty much any implementation of variable variables is just a work
around to using arrays.

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to