how to display array values in php

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

Example 1: foreach loop in php

foreach($array as $key => $value)
  echo $key." has the value". $value;

consider using implode

echo $string;


$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>

Free Live Chat for Any Issue

How to echo or print an array in PHP?

Use the PHP foreach loop

$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 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.