I have an array like this

$data = array(
    "some   => "163",
    "rand"  => "630",
    "om"    => "43",
    "words" => "924",
    "as"    => "4",
    "keys"  => "54"
);

How can I get each set's key associated with their values like this:

foreach ($data as $stuff){
  $this->$stuff["key"] = $stuff["value"];
}
share|improve this question
Very first code block on the very first Google result for "php foreach" yields exactly what you'd expect. – meagar Sep 15 '10 at 23:14

2 Answers

up vote 9 down vote accepted
foreach ($data as $key => $value){
  echo "$key => $value\n";
}
share|improve this answer
foreach($data as $key => $value)
{
    // $key and $value variable are available here
    // First iteration values would be: $key = "some" and $value = "163"
}
share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.