2

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>;
1
  • foreach more suit array looping. Commented Jul 21, 2013 at 22:38

4 Answers 4

3

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();
Sign up to request clarification or add additional context in comments.

Comments

2
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.

Comments

1

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!

3 Comments

Great it works, but know is echoing a ";" along the content, was that suppose to happen?
@MariangelaVidotto: not really. See the last line of your code: </div></div>; -- that might be the issue. :-)
Alright now it's perfect, thank you for the help, I really appreciate it, thank you all.
-1

As a side note, I can see a problem in your last few lines:

echo ' 
</div>
    </div></div>;

Should be:

echo '</div></div></div>';

2 Comments

-1. Having newlines in a single quoted string is not illegal PHP syntax.
But you forgot ' character

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.