This question already has an answer here:
- How can I sort arrays and data in PHP? 10 answers
I have looked in other posts with the same problem but i cand find a solution for my problem...
I just want to sort this array:
private $text = array(
array(1, 'aa', '11'),
array(2, 'cc', '22'),
array(3, 'bb', '33')
);
but sorted by the second value, the string.
my code
class combo {
private $text = array(
array(1, 'aa', '11'),
array(2, 'cc', '22'),
array(3, 'bb', '33')
);
public function combo() {
//UPDATE WITH PERRYs ANSWER
usort($this->text, function ($a, $b) {
return $b[1] < $a[1];
});
$content='<div id="round">'.
'<div class="round1">'.
'<select>';
for( $i=0; $i<=3; $i++ )
{
$content.= '<option value="' . utf8_encode($this->text[$i][0]) . '">' . utf8_encode($this->text[$i][1]) . '</option>';
}
$content.='</select>';
$content.='</div>';
$content.='</div>';
return $content;
}
}
thanks!
Rafael S.
</div>