Preprocezzor
Preprocezzor

Reputation: 307

Echo Arrays in Array

I have an Array with mutltiple Arrays in it. I tried to echo each of them but I get "Array" instead of the values which are saved inside of each Arrays.

My Array looks like this:

$arrays = [['test1','test2'],['test3','test4']];

foreach($arrays as $array) {
       echo $array, '<br>';
}

I get:

Array
Array 

instead of

test1,test2
test3,test4

Upvotes: 0

Views: 5275

Answers (4)

Aleks G
Aleks G

Reputation: 57306

You're not printing the content of inner arrays - try this:

$arrays = [['test1','test2'],['test3','test4']];

foreach($arrays as $array) {
    echo implode(',', $array) . '<br>';
}

Oh, and why not just print_r($arrays)?

Upvotes: 5

Gobinath Manokaran
Gobinath Manokaran

Reputation: 56

Use print_r($array)

It prints all the inner arrays within an array

Upvotes: 0

Tobias Golbs
Tobias Golbs

Reputation: 4616

This could be a possible way to print your data:

foreach($arrays as $array) {
    foreach($array as $value) {
        echo $value . ",";
    }
    echo "<br />";
}

Upvotes: 0

ex3v
ex3v

Reputation: 3566

Try this

echo "<pre>";
  var_dump($arrays); 
echo "</pre>";

update

Convinient way to use this is to make shortcut in your IDE. For example in NetBeans when I want to var_dump something, I just type vdp and press Tab. You will find NetBeans shortcuts under Tools->Options->Editor->Code Templates.

Upvotes: 0

Related Questions