3

私は配列を持っていて、作成されたフィールドに従って並べ替えたいのですが、いくつかのコードで並べ替えようとしましたが、これができないので助けてください.

Array 
(
[0] => stdClass Object
    (
        [status_id] => 26
        [message] => this is test
        [created] => 2013-03-05 23:11:54
        [uid] => 1
        [first_name] => sandeep
        [last_name] => singh
    )

[1] => stdClass Object
    (
        [status_id] => 27
        [message] => this is sisfd
        [created] => 2013-09-10 22:28:46
        [uid] => 1
        [first_name] => sandeep
        [last_name] => singh
    )

[2] => stdClass Object
    (
        [status_id] => 28
        [message] => nvcbncvnbcvnbvcnb
        [created] => 2013-09-25 22:29:12
        [uid] => 1
        [first_name] => sandeep
        [last_name] => singh
    )

[3] => stdClass Object
    (
        [status_id] => 29
        [message] => this is time test
        [created] => 2013-09-10 23:08:52
        [uid] => 1
        [first_name] => sandeep
        [last_name] => singh
    )

[4] => stdClass Object
    (
        [status_id] => 30
        [message] => thuiso9safdasdfasdfasdfasdf
        [created] => 2013-09-26 00:41:15
        [uid] => 1
        [first_name] => sandeep
        [last_name] => singh
    )

)

4

3 に答える 3

0

これを試してください:

function array_multi_subsort($array, $subkey)
{
    $b = array(); $c = array();

    foreach ($array as $k => $v)
    {
        $b[$k] = strtolower($v->$subkey);
    }

    asort($b);
    foreach ($b as $key => $val)
    {
        $c[] = $array[$key];
    }

    return $c;
}

// sorting through "created" element in the arrays
$data = array_multi_subsort($array, 'created');
print_r($data);
于 2016-03-17T10:26:44.870 に答える
0

これを試して

 $yourarray = array(array(...), array(....),.....);

 function myFieldSort($a, $b)
 {
   return $b['created'] - $a['created'];
 }

 usort($yourarray, "myFieldSort");
于 2013-09-27T19:45:09.880 に答える