Notice: Array to String Conversion In

How to solve PHP error 'Notice: Array to string conversion in...'

When you have many HTML inputs named C[] what you get in the POST array on the other end is an array of these values in $_POST['C']. So when you echo that, you are trying to print an array, so all it does is print Array and a notice.

To print properly an array, you either loop through it and echo each element, or you can use print_r.

Alternatively, if you don't know if it's an array or a string or whatever, you can use var_dump($var) which will tell you what type it is and what it's content is. Use that for debugging purposes only.

Notice: Array to string conversion in

The problem is that $money is an array and you are treating it like a string or a variable which can be easily converted to string. You should say something like:

 '.... Money:'.$money['money']

php Notice : Array to string conversion in

The elements of $_SESSION['survey_ans'] are arrays, so you need to iterate through the values in each array to get your desired output. Try this:

foreach($_SESSION['survey_ans'] as $result) {
foreach ($result as $key => $value) {
echo $key."-".$value."<br />";
}
}

Output:

1-vpoor
10-poor
6-average
11-good
12-vgood
13-good

Demo on 3v4l.org

I got Error Notice: Array to string conversion in my code php

my problem is solved

by replace

             <td><?php echo $item["authors"]; ?></td>

to

<td><?php echo implode(",", $item["authors"]); ?></td>

Notice: Array to string conversion PHP error, SESSION ARRAYS?

You cannot echo an array.

So you have to implode the array like this:

echo 'Welcome '.implode(" ", $_SESSION['user']);

But this will give you the Warning: implode(): Invalid arguments passed in welcome.php because you unset the $_SESSION['user'] when you logout.

So you have to check it with isset like this:

echo isset($_SESSION['user']) ? 'Welcome '.implode(" ", $_SESSION['user']) : "Whatever you want when user is not logged in";

Notice: Array to string conversion in basic.php on line 1443 Array

you are trying to use print function on $new_data array . you can iterate over each value with a foreach loop and print or you can use print_r function.

print_r($new_data);
//or
foreach($new_data as $key => $value) {
print($value);
}


Related Topics



Leave a reply



Submit