Jump to content
Dioguex

Imprimir Array Key->Value

Recommended Posts

Dioguex

Boa tarde a todos,

Preciso de uma ajuda. Por algum motivo que não estou a conseguir imprimir o conteúdo do array em php.

Com a instrução:

echo <pre>;
print_r ($result);
echo </pre>;

Imprimir o seguinte resultado:

Array
(
[restaurants] => Array
 (
	 [0] => Array
		 (
			 [name] => The Star
			 [type] => Array
				 (
					 [0] => restaurant
					 [1] => food
					 [2] => casino
					 [3] => spa
					 [4] => lodging
					 [5] => point_of_interest
					 [6] => establishment
				 )
			 [vicinity] => 80 Pyrmont Street, Pyrmont
		 )
	 [1] => Array
		 (
			 [name] => South Steyne
			 [type] => Array
				 (
					 [0] => restaurant
					 [1] => food
					 [2] => point_of_interest
					 [3] => establishment
				 )
			 [vicinity] => Harbourside Jetty, Darling Drive, Darling Harbour
		 )
	 [2] => Array
		 (
			 [name] => ibis Sydney Darling Harbour
			 [type] => Array
				 (
					 [0] => restaurant
					 [1] => food
					 [2] => lodging
					 [3] => point_of_interest
					 [4] => establishment
				 )
			 [vicinity] => 70 Murray Street, Pyrmont
		 )
	 [3] => Array
		 (
			 [name] => Blue Fish
			 [type] => Array
				 (
					 [0] => restaurant
					 [1] => food
					 [2] => point_of_interest
					 [3] => establishment
				 )
			 [vicinity] => Harbourside Shopping Centre, Darling Drive, Darling Harbour
		 )
	 [4] => Array
		 (
			 [name] => Flying Fish Restaurant & Bar
			 [type] => Array
				 (
					 [0] => bar
					 [1] => restaurant
					 [2] => food
					 [3] => point_of_interest
					 [4] => establishment
				 )
			 [vicinity] => Lower Deck, Jones Bay Wharf, 21 Pirrama Road, Pyrmont
		 )
	 [5] => Array
		 (
			 [name] => John St Square Supermarket
			 [type] => Array
				 (
					 [0] => food
					 [1] => store
					 [2] => point_of_interest
					 [3] => establishment
				 )
			 [vicinity] => 8/45-55 Harris Street, Pyrmont
		 )

O que eu quero, é imprimir essas informações ou seja, para a primeira opção:

Nome: The Star

Tipo: food, casino, spa, lodging, point_of_interest, establishment

Morada: 80 Pyrmont Street, Pyrmont

Estou a usar o seguinte código:

foreach ($result as $value){
  echo "Nome: ".$value["name"];
  echo "<br>";
  echo "Tipo: ";
  foreach($value->types as $valuearr){
	echo $valuearr["type"];
	echo "<br>";
  }
  echo "Morada: ".$value["vicinity"];
  echo "<br><br>";
}

Mas apenas imprime:

Nome:

Tipo:

Morada:

Que estou a fazer mal para não imprimir as informações?

Obrigado.

P.S. sei que o tipo ainda não está a separar por ",".

Edited by Dioguex

Share this post


Link to post
Share on other sites
tiago.f

O que queres usar é

foreach( $result as $key => $value)

Depois imprimes o key e o value...

Edited by tiago.f

Share this post


Link to post
Share on other sites
Dioguex

Obrigado pela resposta Tiago,

Eu só queria imprimir o value não o key.

Seja como for, obtive o mesmo resultado usando o teu foreach.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.