I have the following function:
function moveUp($row_nr){
$other_row = ($row_nr - 1);
foreach ($this -> data as &$row){
if ($row['row_nr'] == $other_row){
$row['row_nr']++;
}
else if ($row['row_nr'] == $row_nr){
$row['row_nr']--;
}
}
}
$this -> data is an array containing arrays representing rows of fields returned by an SQL query. The purpose of this function is to move the specified row up in the order by decrementing its row_nr and incrementing the row_nr of the row that was originally above it.
Unfortunately things don’t seem to be going to plan though! The row_nr doesn’t seem to update in the object. Looking at other threads I’ve seen people suggesting to use the & operator to reference the variable specifically rather than a copy of it, but as you can see in my code I’ve done that and not had a whole lot of luck with it (or perhaps I’m doing it wrong!).
I’ve also tried the lines:
$row -> row_nr++;
$row -> row_nr--;
as I’ve seen in some examples posted here but no luck there either.
Does anybody have any suggestions as to why the data array in the object doesn’t seem to be updating properly?
1 Answer