Foreach help

Ask about a PHP problem here.
Post Reply
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Foreach help

Post by FrederickGeek8 »

I have an array that is like
Array([GOOG] => 1, [AAPL] => 2);

How can I do a foreach where I can grab the value like GOOG (the list is ordered by the number value)

Thanks,
Fred
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: Foreach help

Post by ExtremeGaming »

It's actually a lot simpler than one would think :) Here's an example.
<?php
$array = array("Test" => "successful"); // Just a sample array

foreach($array as $key => $value) {

echo $key." returned ".$value;  // Displays "Test returned successful"

}
?>
<?php while(!$succeed = try()); ?>
Post Reply