Today, We want to share with you how to display array values in php.In this post we will show you php echo array values foreach, hear for php get all values from multidimensional array we will give you demo and example for implement.In this post, we will learn about How to Print Arrays in PHP? with an example.
Display array values in PHP
Contents
Example 1: foreach loop in php
foreach($array as $key => $value) { echo $key." has the value". $value; }
consider using implode
$string=implode(",",$array); echo $string; //or $withComma = implode(",", $array); echo $withComma; // Will display mobile,laptop,camero
Pre code
<?php $data = array('a'=>'mobile','b'=>'laptop','c'=>'camero');?> <pre><?php print_r($data); ?></pre>
How to echo or print an array in PHP?
Use the PHP foreach loop
<?php $products = array("mobile", "Laptop", "Dasktop", "Pendrive", "DVD"); // Loop through products array foreach($products as $value){ echo $value . "<br>"; } ?>
I hope you get an idea about How to print or echo all the values of an array in PHP?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโt forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.