Home >Backend Development >PHP Tutorial >How Can I Echo Multi-Dimensional Array Contents in PHP Without Showing the Array Structure?
Question:
I have an array with multiple levels of data. How can I display its contents without the array structure?
Code:
$results = [ 'data' => [ [ 'page_id' => 204725966262837, 'type' => 'WEBSITE', ], [ 'page_id' => 163703342377960, 'type' => 'COMMUNITY', ], ] ]; // Unsuccessful attempt foreach ($results as $result) { echo $result->type; echo "\n"; }
Answer:
To display the contents of an array without its structure, you can use one of the following methods:
echo '<pre class="brush:php;toolbar:false">'; print_r($results); echo '';
foreach ($results['data'] as $data) { echo $data['type'] . "\n"; }
The above is the detailed content of How Can I Echo Multi-Dimensional Array Contents in PHP Without Showing the Array Structure?. For more information, please follow other related articles on the PHP Chinese website!