You are here: Re: [PHP] printing keys and values of array « PHP « IT news, forums, messages
Re: [PHP] printing keys and values of array

Posted by tg-php on 10/21/20 11:36

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.

 

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

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