Jump to content
php.lv forumi
Sign in to follow this  
ziedinjsh

php array sakaārtot augošā secībā pēc laika

Recommended Posts

Sveiki, mēģinu panāk, ka no divām tabulām datus saliek kopā un izvad augošā secībā pec laika
 

$comments = ORM::for_table('comments')->where('uid', $id)->find_array();
$replays = ORM::for_table('comment_replays')->where('uid', $id)->find_array();
$opinions = array_merge($comments, $replays);

foreach($opinions as $item => $key){
        echo $item.' = '.$key['time'].'<br>';
}

Share this post


Link to post
Share on other sites

Sakārto pēc abu tabulu komentu timestampiem, tos ņemot kā masīva key. Diez vai būs kāds komentāra timestamp, kas eksistēs abās tabulās.

Array_merge vietā izmanto  $comments + $replays

Share this post


Link to post
Share on other sites

$opinions = array_merge($comments, $replays);

usort($opinions, function ($a, $b)

{

return $a['time'] <=> $b['time']; // PHP 7 spaceship operator

});

Edited by jurchiks

Share this post


Link to post
Share on other sites

Labi, principā es vispār nesaprotu, nafig viņš merdžo un kārto komentārus un replies pēc datumiem, nevis pēc parent id un tikai tad pēc datumiem.

Bet tas ir pie kājas; jautājums bija "kā no divām tabulām datus saliek kopā un izvad augošā secībā pec laika", un uz to ir atbildēts.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...