Home > Net >  Warning: Array to string conversion
Warning: Array to string conversion

Time:03-10

i stuck at a simple Problem i guess.. I try to get all the data from the strings into one Element (like a ul).

Here at my example: i have tried this:

<pre>

<?php
var_dump ($_POST);

foreach ($_POST as $user) {
enter code hereecho $user;
}

?>

</pre>

And this is what i get from the var_dump:

array(1) {
  ["firstUl"]=>
  array(6) {
    [0]=>
    string(5) "Test1"
    [1]=>
    string(5) "Test2"
    [2]=>
    string(5) "Test3"
    [3]=>
    string(5) "Test4"
    [4]=>
    string(5) "Test5"
    [5]=>
    string(5) "Test6"
  }
} 

What i want is that each string is going to a ul

I think its very easy but i can´t find a solution especially to my problem..

CodePudding user response:

You should define the index for your foreach, for example :

foreach ($_POST as $ul) {
    foreach ($ul as $key => $user) {
        echo $user;
    }
}
  • Related