Сначала вам нужно превратить строки в массивы с помощью explode
, чтобы вы могли сделать сравнения:
// If using PHP >= 5.3, this can also be made into an anonymous function
function converter($string) {
$result = array_combine(
array('title', 'url', 'score', 'user', 'date'),
explode('|', $string)
);
// When these are later compared, it should be as numbers
$result['score'] = (int)$result['score'];
return $result;
}
$input = array(
'Foo|http://foo|0|user1|today',
// etc.
);
$converted = array_map('converter', $input);
Это сделает $converted
похожим на:
array (
0 => array (
'title' => 'Foo',
'url' => 'http://foo',
'score' => '0',
'user' => 'user1',
'date' => 'today',
),
)
Затем вы можете отсортировать массив, используя код из моего ответа здесь , легко указав любой критерий сортировки:
usort($converted, make_converter('score', 'date', 'title'));