How to Print Arrays in PHP?

Today, We want to share with you print array in php.In this post we will show you array to string php, hear for php echo array values foreach we will give you demo and example for implement.In this post, we will learn about Dd And Dump – Dd() Vs Var_dump() Vs Print_r()
with an example.

Echo or Print an Array in PHP

Syntax:

print_r(variable, isStore)


Example 1: readable way by using html <pre> tag.

<?php

$upcomming_movies_website = array("0" => "pakainfo.com", "1" => "is", "2" => "a", "3" => "good",
"4" => "tutorial", "5" => "blog", "6" => "site");

$results = print_r($upcomming_movies_website,true);

echo "<pre>";
echo $results;
echo "</pre>";

?>

Example 2:

<?php

//Declare the array
$upcomming_movies_website = array("Name" => "pakainfo.com", "type" => "upcomming movies site","content" =>
array("Tamilrokers","khatrimaza","bolly4u"));

//print the structure of the array
print_r($upcomming_movies_website);

?>

print array in php

Example 1:

$upcomming_movies_website = array ('a' => 'Tamilrokers', 'b' => 'khatrimaza', 'c' => array ('x', 'y', 'z'));
print_r ($upcomming_movies_website);

Example 2:

<?php
$upcomming_movies_website = array ('a' => 'Tamilrokers', 'b' => 'khatrimaza', 'c' => array ('x', 'y', 'z'));
print_r ($upcomming_movies_website);
?>

Example 3:

<?php
$upcomming_movies_website = array("Tamilrokers", "khatrimaza", "bolly4u");
echo "I like " . $upcomming_movies_website[0] . ", " . $upcomming_movies_website[1] . " and " . $upcomming_movies_website[2] . ".";
?>

Example 4:

foreach($results as $result) {
	echo $result . '<br>';
}

I hope you get an idea about php foreach ($array).
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.