I am receiving an error once this code runs. I have looked up possible solutions but everything seems to be formatted correctly.

$searched = 'searched';    
$count    = '59';
$prop     = Array();

$i = 0;
while ($i++ <= 4) {
    array_push($prop[$i] = Array(
         'text' => $searched,
         'href' => 'http://mysite.com/?search=' . str_replace(' ', '+', $searched)
    ));
}

array_push($prop['Total Searches'] = $count);

I receive this error 5 times for the while loop, and 1 time for the array_push under the while loop.

Warning: Wrong parameter count for array_push()

The code works correctly! but it still calls out the error. So should I just suppress the error?

Comments

I altered your formatting a bit to make it vaguely legible. Next time, please go ahead and do that yourself!

-1 for considering "just suppress[ing] the error". +1 for realising that it might not be a good idea, and asking about it. :)

Thank you, I couldn't figure out how the back ticks worked. Im going to create an account here since I received an answer so swiftly

Written by Tj tarmon

SO is pretty awesome.

Accepted Answer

Change:

array_push($prop['Total Searches'] = $count);

to:

$prop['Total Searches'] = $count;

etc.

You only use array_push to push a value on to the end of a list-style array. This is not relevant here, as you're just setting a new key/value pair.

Written by dkamins
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki