How to Solve PHP Error '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.

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

How to fix Array to string conversion error

$diurno=isset($_POST['diurno']) ? (array) $_POST['diurno'] : '';
if (is_array($diurno)) {
$diurno = implode('|', $diurno);
}

Try with this code. I think will work properly.
You receive that error because you are trying to save to database, but this value is array and you cannot save it to the database.
You have a two option to implode values with unique delimeter and then save $select to the database or to convert array to json and save it to the database and after that you can use data.

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>

php function returns Warning: Array to string conversion in

As stated above, the $userDisplayData variable is an array, and you are trying to assign a string space to it.

You could do it this way:

function getSwipableUsers() {
$expInt = explode(',', $f['interests']);

$userDisplayData = '<div class="tagsection">';

foreach($expInt as $ints){
$userDisplayData .= "<div class='tag alert-primary'>".$ints."</div>";
}

$userDisplayData .= '</div>';

$html = '<div class="user-distance mt-2">'.$userDisplayData.'</div>';

return $html;
}


Related Topics



Leave a reply



Submit