Reputation: 89
That might be a fool question, but I need to know how to solve this: Notice: Array to string conversion in C:\xampp\htdocs\search_view.php on line 248 Why am I getting this message, what can I do to solve it?
echo'<div id="thumb">
'.$ids = array();
$ids[] = $results['idGames'];
for ($i = 0; $i < count($ids); $i++) {
$id = $ids[$i];
$v = $results['total_votes'];
$tv = $results['total_value'];
if ($v)
$rat = $tv / $v;
else
$rat = 0;
$j = $ids[$i];
$id = $ids[$i];
echo '<div class="topcontentstar">
<div id="' . $id . '" class="">';
for ($k = 1; $k < 6; $k++) {
if ($rat + 1 > $k)
$class = "" . $k . " ratings_stars_index ratings_vote";
else
$class = "" . $k . " ratings_stars_index ratings_blank";
echo '<div class="' . $class . '"></div>';
}
echo '
</div>
</div></div>;
Upvotes: 2
Views: 6230
Reputation:
Because in this part of code you tried to convert an array to string via concatenation
echo'<div id="thumb">
(line 248) '.$ids = array();
Separate them: $ids = array()
echo'<div id="thumb">
(line 248) ';
$ids = array();
Upvotes: 3
Reputation: 76636
You're doing this:
echo'<div id="thumb">
(line 248) '.$ids = array();
Basically, you can't concatenate array with a string and that's why the error appears.
To fix the error, you can separate the array declaration into a separate line:
echo'<div id="thumb">';
$ids = array();
Hope this helps!
Upvotes: 1
Reputation: 1793
As a side note, I can see a problem in your last few lines:
echo '
</div>
</div></div>;
Should be:
echo '</div></div></div>';
Upvotes: -1
Reputation: 11951
echo'<div id="thumb">
(line 248) '.$ids = array();
You are concatenating a string and an array, just as the errors says. You are echoing the string, and appending the array $ids
to that. Because assigning a value gets a higher precedence than concatenating things, $ids
is already an array.
Upvotes: 2