1

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.

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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";
}

Comments

0

You can try print_r() instead of echo.

2 Comments

I don't want to see them only,i want to display the value of SKU as text
so u want to like display all the values as a sentence right? if that's what you want you can try implode() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.