How Can I Echo Or Print An Array In PHP?

To echo or print an array in PHP, you can use the print_r() function or the var_dump() function.

Here is an example using print_r():

$array = [1, 2, 3, 4, 5];
print_r($array);

The output will be:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

And here is an example using var_dump():

$array = [1, 2, 3, 4, 5];
var_dump($array);

The output will be:

array(5) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
}

Both print_r() and var_dump() are useful for debugging purposes, as they provide detailed information about the array’s structure and values.

About the Author Rex

I'm a passionate tech blogger with an insatiable love for programming! From my early days tinkering with code, I've delved into web dev, mobile apps, and AI. Sharing insights and tutorials with the world is my joy, connecting me to a global community of like-minded tech enthusiasts. Python holds a special place in my heart, but I embrace all challenges. Constantly learning, I attend tech conferences, contribute to open-source projects, and engage in code review sessions. My ultimate goal is to inspire the next generation of developers and contribute positively to the ever-evolving tech landscape. Let's code together!