Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Printing Associative Array

In PHP, I have an associative array like this

$a = array('who' => 'one', 'are' => 'two', 'you' => 'three'); 

How to write a foreach loop that goes through the array and access the array key and value so that I can manipulate them (in other words, I would be able to get who and one assigned to two variables $key and $value?

like image 451
Tu Hoang Avatar asked Jun 21 '11 16:06

Tu Hoang


1 Answers

foreach ($array as $key => $value) {     echo "Key: $key; Value: $value\n"; } 
like image 56
Thiago Silveira Avatar answered Sep 18 '22 22:09

Thiago Silveira