So I have a string with comma separated values:
$accounts = "1,2,3,4,5,6";
And I want to reverse that order. So I wrote this:
$accountsrev = implode(',',rsort(explode(',',$accounts)));
Basically I convert to an array, reverse the array, and implode it back into a string. What's wrong with that?
I get a load of errors like this:
Strict Standards: Only variables should be passed by reference in /home/username/public_html/file.php on line 121
Warning: implode(): Invalid arguments passed in /home/username/public_html/file.php on line 121
Edit:
Now I wonder if the way I build the $accounts variable is wrong. I pull 7 rows from the database and then build the $accounts variable in a while loop. The id
is an integer in the database:
$accounts = '';
$i = 1;
while ($data = $getdata->fetch(PDO::FETCH_ASSOC)) {
if ($i < 7) {
$accounts .= $data['id'].',';
} else {
$accounts .= $data['id'];
}
$i++;
}
Does the way I make the $accounts variable not produce a string?