How to print the second value of an array?

Asked

Viewed 85 times

1

I have this array and want to put on the screen the string "Banana".

$frutas = array (
"frutas" => array("a"=>"Laranja", "b"=>"Banana", "c"=>"Maçã"),
"numeros" => array(1, 2, 3, 4, 5, 6),
"buracos" => array("primeiro", 5 => "segundo", "terceiro")
);

How can I do that?

  • You have a array of arrays. You know how to work with arrays? Because it wasn’t very clear exactly what the problem is. Do you want to know just how you access a specific value? Have you read the documentation on array?

  • 1

    No, I don’t know, I’m studying, I can ask this question here or is it too simple?

  • You can, no problem. I only ask because it is difficult to infer the level of knowledge of the questioner and when it is not so clear what is being asked, it becomes confused. You quote the second value and then says that you need a value of a array associative. This doesn’t make much sense because PHP doesn’t guarantee the order of a array associative, then the second value could vary. But yes, feel free to create a question whenever you need.

  • So I can’t get exactly the second value? Cool, I learned one more thing, vlw.

  • How can I send you a question I have directly?

  • In that case, banana would be the value associated with the key b of array that is associated with the key fruit of $frutas, not necessarily the second value (visually is the second, but not necessarily in memory).

  • Can enter the chat Stack Burst.

Show 2 more comments

1 answer

4


Simple as that:

echo $frutas["frutas"]["b"];
  • 1

    Thanks, I’m starting now, I’m even ashamed of so simple.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.