Echo PHP Array: 10 Code Examples to Print Keys & Values (2023)

How to echo an array in PHP
How to echo an array in PHP There are multiple ways to echo arrays in PHP. Use a foreach loop, implode, print_r, or var_dump functions to display an array's keys & values. I recommend using either var_dump or print_r if you are debugging whereas loops are useful when you need to access the data. This article explains how to echo an array in PHP and includes a section about how we can print out a PHP array. Stick to the article and you will have better insights by the end of this article. Let’s start without any further ado. Echo PHP Arrays with Value PHP Code Examples <?php $fruit = ["apple" => 2, "banana" => 3, "orange" => 7]; // Print an array using var_dump: var_dump($fruit); // Print an array using print_r: print_r($fruit); // Echo array keys using a foreach loop. echo "fruits: "; $i = 1; foreach ($fruit as…

read more