[thelist] PHP Multidimensional Array Keys

Les Lytollis leslytollis at dimensions-corporatewear.co.uk
Tue Sep 30 08:39:30 CDT 2003


Sorry, 

Function params should be 

function get_array_elems($arrResult, $where = "array") 

-----Original Message-----
From: Les Lytollis 
Sent: 30 September 2003 14:35
To: thelist at lists.evolt.org
Subject: RE: [thelist] PHP Multidimensional Array Keys


Untested for many years, but from memory, I think a bit of good ol'
recursion is what you want:

function get_array_elems($arrResult){ 
           while(list($key,$value)=each($arrResult)){ 
                 if (is_array($value)){ 
                    get_array_elems($value, $where . "[$key]"); 
                 } 
                 else { 
                       for ($i=0; $i<count($value);$i++){ 
                             echo $where . "[$key]=" . $value; 
                      } 
                 } 
           } 
} 


get_array_elems($arrResult);


-----Original Message-----
From: Gavin Lilley [mailto:gavin at crispuk.net] 
Sent: 30 September 2003 10:47
To: thelist at lists.evolt.org
Subject: [thelist] PHP Multidimensional Array Keys


I am a little stuck with an array. Please help!


matrixArray [Array
(
    [1] => Array
        (
            [unitName] => Unit 2
            [15] => Array
                (
                    [topicName] => Tutorial
                    [2] => Array
                        (
                            [matrixKey] => 16
                            [hours] => 16.00
                        )

                )

            [12] => Array
                (
                    [topicName] => Induction
                    [1] => Array
                        (
                            [matrixKey] => 17
                            [hours] => 6.00
                        )

                    [4] => Array
                        (
                            [matrixKey] => 18
                            [hours] => 44.00
                        )

                )

        )

)

To loop through the array I can do this:
while (list($key, $value) = each ($unitArray)) { echo "[$key ][ $value
]<br>";} But I do not know how to 'drill down' through the array. Whats
wrong with the following code?

while (list($key, $value) = each ($unitArray)) {
 echo "[$key ][ $value ]<br>";
    while (list($keyA, $valueA) = each ($unitArray[$key])) {
     echo "[$keyA ][ $valueA ]<br>";
    }
}

Appreciate any help.

-- 
G.

-- 
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 



********************Confidentiality Notice & Disclaimer
*********************** This message, together with any attachments, is
for the confidential and exclusive use of the addressee(s). If you
receive it in error, please delete the message and its attachments from
your system immediately and notify us by return e-mail. Do not disclose,
copy, circulate or use any information contained in this e-mail.

(1) Whilst we have taken reasonable precautions to ensure that any
attachment to this e-mail has been swept for viruses, we cannot accept
liability for any damage sustained as a result of software viruses and
would advise that you carry out your own virus checks before opening any
attachment.
(2) The sender shall remain solely accountable for any statements,
representations or opinions that are clearly his or her own and not made
in the course of employment.
************************************************************************
***********

-- 
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 



********************Confidentiality Notice & Disclaimer ***********************
This message, together with any attachments, is for the confidential and exclusive use of the addressee(s).
If you receive it in error, please delete the message and its attachments from your system immediately and notify us by return e-mail.
Do not disclose, copy, circulate or use any information contained in this e-mail.

(1) Whilst we have taken reasonable precautions to ensure that any attachment to this e-mail has been swept for viruses, we cannot accept liability for any damage sustained as a result of software viruses and would advise that you carry out your own virus checks before opening any attachment.
(2) The sender shall remain solely accountable for any statements, representations or opinions that are clearly his or her own and not made in the course of employment.
***********************************************************************************



More information about the thelist mailing list