Reputation: 334
I have a product array that is coming from a database.
I just want to print all the variables that are called [sku] inside that said array.
If I print it out like this
<?php echo $products[0]['sku']; ?>
I get only the 1-st value of SKU
how can i display all of the SKU variables without going [0] , [1] , [2] and so on.
Upvotes: 1
Views: 34
Reputation: 31
You can try print_r, but that will give you all the array values. A simple foreach will do the job and only print the SKU for every product.
foreach($products as $value) {
echo $value['sku'] . "\n";
}
Upvotes: 1
Reputation: 46
I think this will do what you want
<?php
foreach ($products as $key => $row) {
var_export($row['sku']);
}
http://php.net/manual/en/control-structures.foreach.php
Upvotes: 3