$GLOBALS['maxPrice']) { return false; } return true; }); $products = array_combine(range(0, count($products) - 1), $products); for($i = 0; $i < count($products) ;$i++) { $currLine = explode('|', $products[$i]); $currLine = array_filter($currLine, function($val) { if($val == "") { return false; } return true; }); $newEntry = new stdClass(); $newEntry->name = trim($currLine[0]); $newEntry->type = trim($currLine[1]); $newEntry->comps = trim($currLine[2]); $newEntry->price = trim(number_format(floatval($currLine[3]), 2, '.', '')); $newEntry->id = trim($currLine[4]); $arrayOfProducts[] = $newEntry; } usort($arrayOfProducts, function($s1, $s2) use ($order, $property) { if ($s1->$property == $s2->$property) { return strcmp($s1->id, $s2->id); } return ($order == "ascending" ^ $s1->$property < $s2->$property) ? 1 : -1; }); for($i = 0; $i < count($arrayOfProducts) ;$i++) { $components = explode(", ", $arrayOfProducts[$i]->comps); echo '