I am trying to consume an Amazon Product API and I choose to search for books alone base on the user search query. However after converting the response to an array, I am having problem looping through all the result without having to specify an index. Below is my Code:
<div class="album py-5 bg-light">
<div class="container">
<div class="row">
<?php
foreach($formattedResponse as $response) {
?>
<div class="col-md-8">
<div class="card mb-4 box-shadow">
<img class="card-img-top" data-src="" alt="Card image cap">
<div class="card-body">
<p class="card-text"></p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-secondary">Arthur: <?php echo $response['Item'][0]['ItemAttributes']['Author']; ?></button>
<button type="button" class="btn btn-sm btn-outline-secondary">Title: <?php echo $response['Item'][0]['ItemAttributes']['Title']; ?></button>
</div>
<small class="text-muted">Price: <?php echo $response['Item'][0]['ItemAttributes']['ListPrice']['FormattedPrice']; ?> </small>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>
Displaying the results works perfectly, the only drawback is, it fetches only the first index of the returned book response out of the thousands present because I used $response['Item'][0]
if I take away the [0]
from I get an error.. Below is the result
Arthur: Harry Boone Porter
Title: The Day of Light
Price: $8.00
My Question: The array contains [0],[1],[2] to [1000] How can I fetch all the book results in the above format instead of the first index which I am using.
Here is my Array Code Snippet: https://pasteio.com/xlsoTVWJLGBO