1

I have an array $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);. How can i get (echo) all names and corresponding ages in a single instance (like foreach $value as $value)?? The array may have more data than shown here.

4 Answers 4

7
foreach ($ages as $name => $age) {
echo "$name = $age\n";
}
Sign up to request clarification or add additional context in comments.

Comments

2

u have a lot options

like

print_r

print_r($array)

var_dump , foreach

Comments

2
print_r($array);

or

var_dump($array)

Comments

1
foreach ($ages as $key => $value) {
  echo $key . "'s age is " . $value . "<br />";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.