My array stores these variables:$arrgames = [$gametitle, $description, $releaseDate $score, $image]
I have made the array from an object and am trying to sort them in highest to lowest $score
. Through research this is the furthest I could get to making the bubble sort:
$tgameslist = DAL_CreateGames();
$arrgames = [];
foreach ($tgameslist->gameitems as $tgitem) {
array_push($arrgames, $tgitem);
}
$size = count($arrgames) - 1;
for ($i = 0; $i > 3; $i ++) {
for ($j = 0; $j < $size; $j ++) {
$position = $j + 1;
if ($arrgames[$position] < $arrgames[$j]) {
list ($arrgames[$j], $arrgames[$position]) = array(
$arrgames[$position],
$arrgames[$j]
);
}
}
}
But with the code above I don't know how to pretty much tell it which part of the array needs to be compared(score)
What I am essentially trying to do is
$tgamedata[] = new BLLGameItem(3, "Fifa 20", "blah blah", "Sep 24, 2019", "79", "fifa20.jpg");
$tgamedata[] = new BLLGameItem(1, "GTA V", "blah blah", "Nov 18, 2014", "97", "gtaV.jfif");
Sort these by their score ("79" and "97") in a function and return them sorted