Re: printing keys and values of array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I agree with the previous responder, foreach() is the way to go. Here's the doc page:

http://uk2.php.net/manual/en/control-structures.foreach.php


To get the keys, use the examples that are use $key => $value.


Assuming your array is in $infoArr, you'd do this:

foreach ($infoArr as $category => $data) {

  echo "$category:$data<br>\n";

}


Also, if you ever needed to get just the keys or just the values of an array, you can use:

array_keys()
and
array_values()

Both return an array.

Good luck!

-TG

= = = Original message = = =

Hi
i need some help with printing an array, i would like to print the
keys and the values of them
example :

if i have an array like that

------------------------
[EXTENDED] => Array
                        (
                            [RTCode] => CASE395
                            [ManuPartNum] => 1BRA1ACFB
                            [Colour] => WHITE
                            [Compatibility] => (ATX/E ATX)
                            [PowerSupply] => YES
                            [PowerSupplySize] => redundant 337W2
                            [ExtDriveBays] => 3 x 5.25 1 x 3.5
                            [IntDriveBays] => 6 x 5.25
                            [USBPortsFront] => no
                            [FirewirePortsFront] => no
                            [AudioPortsFront] => no
                            [CaseFan] => 8cm FAN2  12cm FAN1  P/S2
                            [NumCaseFans] => 5
                            [FreeCaseFanPoints] => No
                            [Material] => Stainless steel
                            [Window] => No
                            [Packaging] => Retail
                            [Warranty] => 24 months for the PSU
                            [BoxContents] => Manual
                            [CartonHeight] => 735mm
                            [CartonWidth] => 285mm
                            [CartonDepth] => 585mm
                            [ItemsPerCarton] => 1
                            [CartonWeight] => 1.6kg
                            [EAN] =>
                            [BoxWeight] =>
                            [ItemHeight] =>
                            [ItemWidth] =>
                            [ItemDepth] =>
                        )
------------------------
and i like to print it this way
------------------------
RTCode:CASE395
ManuPartNum] :1BRA1ACFB
Colour] :WHITE
Compatibility :(ATX/E ATX)
PowerSupply :YES
PowerSupplySize:redundant 337W2
ExtDriveBays:3 x 5.25 1 x 3.5
IntDriveBays:6 x 5.25
USBPortsFront:no
FirewirePortsFront:no
AudioPortsFront:no
CaseFan:8cm FAN2  12cm FAN1  P/S2
NumCaseFans:5
FreeCaseFanPoints] => No
Material :Stainless steel
Window :No
Packaging:Retail
Warranty:24 months for the PSU
BoxContents:Manual
CartonHeight:735mm
CartonWidth:285mm
CartonDepth:585mm
ItemsPerCarton:1
CartonWeight:1.6kg
EAN:
BoxWeight:
ItemHeight:
ItemWidth:
ItemDepth:
------------------------
can anyone tell me plz how to do that ?
any help would be appreciated

thanks in advance

--
Ahmed Abdel-Aliem
Web Developer
www.SafariStudio.net
+20101108551
registered Linux user number 382789


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux