-4

I am using array_diff correctly to compare 2 arrays.

In documentation, it says the output is like this:

Array
(
   [1] => blue
)

As you can see, each output will come in a single line.

But when I try it, it only shows me output in 1 line.

enter image description here

Maybe now can be a little friendly, because I only have 4 rows to compare, but I'm supposed to have, in the future, hundreds of them.

How could I solve this?

Tárraga
  • 461
  • 1
  • 6
  • 13

4 Answers4

2

You can "pretty print" your array:

echo "<pre>";
print_r($myArray);
echo "</pre>";
Daan
  • 12,099
  • 6
  • 34
  • 51
1

the "pre" is used to print pretty arrays

print "<pre>";
print_r($array);
print "</pre>";

PHP manual

Aniruddha Chakraborty
  • 1,849
  • 1
  • 20
  • 32
0

Use print or echo and print <pre> and </pre> while array printing:

print "<pre>";
print_r($myArray);
print "</pre>";
Jayesh Chitroda
  • 4,987
  • 13
  • 18
0

Both results are same, the first result is printed using <pre> tag with print_r($array).

So you can get the output like second result using,

<?php
    echo "<pre>";
    print_r(array_diff($array1, $array2));
    echo "</pre>";

print_f and arraydiff

Aniruddha Chakraborty
  • 1,849
  • 1
  • 20
  • 32
Alok Patel
  • 7,842
  • 5
  • 31
  • 47