Dioguex Posted January 23, 2016 at 03:45 PM Report Share #592404 Posted January 23, 2016 at 03:45 PM (edited) 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 January 23, 2016 at 03:48 PM by Dioguex Link to comment Share on other sites More sharing options...
tiago.f Posted January 23, 2016 at 03:52 PM Report Share #592405 Posted January 23, 2016 at 03:52 PM (edited) O que queres usar é foreach( $result as $key => $value) Depois imprimes o key e o value... Edited January 23, 2016 at 03:52 PM by tiago.f Link to comment Share on other sites More sharing options...
Dioguex Posted January 23, 2016 at 04:04 PM Author Report Share #592406 Posted January 23, 2016 at 04:04 PM 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now