fork download
  1. <?php
  2.  
  3. $data = json_decode('[{"artist":"Lee Fields & The Expressions", "title":"Stone Angel (Instrumental)", "time":"5:09", "url":"http://m...content-available-to-author-only...o.net/getsong/122969125908759"}, {"artist":"Justin Hurwitz, Ryan Gosling & Emma Stone", "title":"City Of Stars / May Finally Come True", "time":"4:17", "url":"http://m...content-available-to-author-only...o.net/getsong/123005062041973"}, {"artist":"Lee Fields & The Expressions", "title":"Stone Angel", "time":"5:09", "url":"http://m...content-available-to-author-only...o.net/getsong/122970798940574"}, {"artist":"Ryan Gosling & Emma Stone", "title":"A Lovely Night", "time":"3:56", "url":"http://m...content-available-to-author-only...o.net/getsong/123007812887006"}, {"artist":"Ryan Gosling, Emma Stone", "title":"A Lovely Night", "time":"3:56", "url":"http://m...content-available-to-author-only...o.net/getsong/123005983392032"}, {"artist":"Ryan Gosling feat. Emma Stone", "title":"City of Stars", "time":"2:29", "url":"http://m...content-available-to-author-only...o.net/getsong/123007812944364"}, {"artist":"Lee Fields", "title":"Stone Angel", "time":"5:08", "url":"http://m...content-available-to-author-only...o.net/getsong/76881833722168"}, {"artist":"Justin Hurwitz", "title":"City of Stars (Humming) [feat. Emma Stone]", "time":"2:43", "url":"http://m...content-available-to-author-only...o.net/getsong/123005061947742"}, {"artist":"Shogun Feat. Emma Lock", "title":"Save Me (Stoneface & Terminal Vocal Mix)", "time":"6:25", "url":"http://m...content-available-to-author-only...o.net/getsong/122894434038111"}, {"artist":"Shogun feat. Emma Lock", "title":"Save Me (Stoneface & Terminal vocal mix)", "time":"8:51", "url":"http://m...content-available-to-author-only...o.net/getsong/48288951345578"}, {"artist":"Heuse", "title":"Stones (feat. Chris Linton & Emma Sameth)", "time":"2:55", "url":"http://m...content-available-to-author-only...o.net/getsong/123006010822985"}, {"artist":"Emma Deigman", "title":"Tell Your Mama Stonebridge Club Remix", "time":"7:21", "url":"http://m...content-available-to-author-only...o.net/getsong/73791306678772"}, {"artist":"Emma Stone/Ryan Gosling", "title":"A Lovely Night", "time":"3:57", "url":"http://m...content-available-to-author-only...o.net/getsong/123000854442439"}, {"artist":"Emma Stone, Callie Hernandez, Sonoya Mizuno, Jessica Rothe", "title":"Someone in the Crowd", "time":"4:19", "url":"http://m...content-available-to-author-only...o.net/getsong/123005983252990"}, {"artist":"Emma Stone", "title":"Someone In The Crowd", "time":"4:19", "url":"http://m...content-available-to-author-only...o.net/getsong/123006180020645"}, {"artist":"Cosmic Gate", "title":"London Rain (Stoneface & Terminal Remix)", "time":"7:47", "url":"http://m...content-available-to-author-only...o.net/getsong/39550523491444"}, {"artist":"Cosmic Gate", "title":"London Rain (Ruben De Ronde Remix)", "time":"3:08", "url":"http://m...content-available-to-author-only...o.net/getsong/122880090461253"}, {"artist":"Cosmic Gate", "title":"London Rain (Stoneface And Terminal Remix)", "time":"7:47", "url":"http://m...content-available-to-author-only...o.net/getsong/122880090465350"}, {"artist":"Marcus Schossow & Reeves feat. Emma Hewitt", "title":"Light (Stoneface & Terminal Dub Remix)", "time":"6:36", "url":"http://m...content-available-to-author-only...o.net/getsong/39661642282135"}, {"artist":"Shogun feat. Emma Lock", "title":"Save Me (Stoneface & Terminal Vocal Mix)", "time":"8:51", "url":"http://m...content-available-to-author-only...o.net/getsong/72160898405493"}, {"artist":"Marcus Schossow & Reeves feat. Emma Hewitt", "title":"Light (Stoneface & Terminal Vocal Remix)", "time":"6:57", "url":"http://m...content-available-to-author-only...o.net/getsong/39661639124116"}, {"artist":"Cosmic Gate", "title":"Sometimes They Come Back for More (Stoneface & Terminal Remix)", "time":"7:42", "url":"http://m...content-available-to-author-only...o.net/getsong/40093022577894"}, {"artist":"Emma Stone", "title":"Audition (The Fools Who Dream)", "time":"3:48", "url":"http://m...content-available-to-author-only...o.net/getsong/123000851829065"}, {"artist":"Emma Stone", "title":"ВЕРНУТЬ ВСЁ НАЗАД", "time":"4:29", "url":"http://m...content-available-to-author-only...o.net/getsong/64228794990888"}, {"artist":"Emma Stone", "title":"Knock on wood", "time":"1:29", "url":"http://m...content-available-to-author-only...o.net/getsong/49766552949085"}, {"artist":"Emma Stone", "title":"Audition (The Fools Who Dream)", "time":"3:48", "url":"http://m...content-available-to-author-only...o.net/getsong/123005982970297"}, {"artist":"Emma Stone", "title":"ВО СНАХ", "time":"6:01", "url":"http://m...content-available-to-author-only...o.net/getsong/64229208625569"}, {"artist":"Emma Stone", "title":"City Of Stars", "time":"2:29", "url":"http://m...content-available-to-author-only...o.net/getsong/123006871019938"}, {"artist":"Armin van Buuren", "title":"Stone Cold [Asot Radio Classic]", "time":"6:04", "url":"http://m...content-available-to-author-only...o.net/getsong/66306144887910"}]');
  4.  
  5. $search = "Emma Stone";
  6. $words = explode(" ", $search);
  7.  
  8. function reorder(&$m) {
  9. global $words, $search;
  10. for ($i = 0; $i < count($m); $i++) {
  11. if (preg_match('/^'.$search.'(\\s|$)/', $m[$i]->artist) || preg_match('/^'.$search.'(\\s|$)/', $m[$i]->title)) $m[$i]->rel = 1;
  12. else if (preg_match('/\\s'.$search.'(\\s|$)/', $m[$i]->artist) || preg_match('/\\s'.$search.'(\\s|$)/', $m[$i]->title)) $m[$i]->rel = 0.8;
  13.  
  14. else {
  15. for ($j = 0; $j < count($words); $j++) {
  16. if (preg_match('/(^|\\s)'.$words[$j].'(\\s|$)/', $m[$i]->artist) && preg_match('/(^|\\s)'.$words[$j].'(\\s|$)/', $m[$i]->title)) {
  17. $m[$i]->rel = 0.7;
  18. break;
  19. }
  20. if (preg_match('/(^|\\s)'.$words[$j].'(\\s|$)/', $m[$i]->artist) || preg_match('/(^|\\s)'.$words[$j].'(\\s|$)/', $m[$i]->title)) {
  21. $m[$i]->rel = 0.6;
  22. break;
  23. }
  24. }
  25. }
  26.  
  27. if (!isset($m[$i]->rel)) $m[$i]->rel = 0.4;
  28. }
  29.  
  30. usort($m, function($a, $b) {
  31. if ($a->rel == $b->rel) return 0;
  32. return $a->rel < $b->rel ? 1 : -1;
  33. });
  34. }
  35.  
  36. reorder($data);
  37. print_r($data);
  38.  
  39. ?>
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
Array
(
    [0] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => Knock on wood
            [time] => 1:29
            [url] => http://m...content-available-to-author-only...o.net/getsong/49766552949085
            [rel] => 1
        )

    [1] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => ВЕРНУТЬ ВСЁ НАЗАД
            [time] => 4:29
            [url] => http://m...content-available-to-author-only...o.net/getsong/64228794990888
            [rel] => 1
        )

    [2] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => Audition (The Fools Who Dream)
            [time] => 3:48
            [url] => http://m...content-available-to-author-only...o.net/getsong/123005982970297
            [rel] => 1
        )

    [3] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => ВО СНАХ
            [time] => 6:01
            [url] => http://m...content-available-to-author-only...o.net/getsong/64229208625569
            [rel] => 1
        )

    [4] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => City Of Stars
            [time] => 2:29
            [url] => http://m...content-available-to-author-only...o.net/getsong/123006871019938
            [rel] => 1
        )

    [5] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => Audition (The Fools Who Dream)
            [time] => 3:48
            [url] => http://m...content-available-to-author-only...o.net/getsong/123000851829065
            [rel] => 1
        )

    [6] => stdClass Object
        (
            [artist] => Emma Stone
            [title] => Someone In The Crowd
            [time] => 4:19
            [url] => http://m...content-available-to-author-only...o.net/getsong/123006180020645
            [rel] => 1
        )

    [7] => stdClass Object
        (
            [artist] => Ryan Gosling & Emma Stone
            [title] => A Lovely Night
            [time] => 3:56
            [url] => http://m...content-available-to-author-only...o.net/getsong/123007812887006
            [rel] => 0.8
        )

    [8] => stdClass Object
        (
            [artist] => Justin Hurwitz, Ryan Gosling & Emma Stone
            [title] => City Of Stars / May Finally Come True
            [time] => 4:17
            [url] => http://m...content-available-to-author-only...o.net/getsong/123005062041973
            [rel] => 0.8
        )

    [9] => stdClass Object
        (
            [artist] => Ryan Gosling feat. Emma Stone
            [title] => City of Stars
            [time] => 2:29
            [url] => http://m...content-available-to-author-only...o.net/getsong/123007812944364
            [rel] => 0.8
        )

    [10] => stdClass Object
        (
            [artist] => Ryan Gosling, Emma Stone
            [title] => A Lovely Night
            [time] => 3:56
            [url] => http://m...content-available-to-author-only...o.net/getsong/123005983392032
            [rel] => 0.8
        )

    [11] => stdClass Object
        (
            [artist] => Marcus Schossow & Reeves feat. Emma Hewitt
            [title] => Light (Stoneface & Terminal Dub Remix)
            [time] => 6:36
            [url] => http://m...content-available-to-author-only...o.net/getsong/39661642282135
            [rel] => 0.6
        )

    [12] => stdClass Object
        (
            [artist] => Shogun feat. Emma Lock
            [title] => Save Me (Stoneface & Terminal Vocal Mix)
            [time] => 8:51
            [url] => http://m...content-available-to-author-only...o.net/getsong/72160898405493
            [rel] => 0.6
        )

    [13] => stdClass Object
        (
            [artist] => Lee Fields & The Expressions
            [title] => Stone Angel
            [time] => 5:09
            [url] => http://m...content-available-to-author-only...o.net/getsong/122970798940574
            [rel] => 0.6
        )

    [14] => stdClass Object
        (
            [artist] => Lee Fields
            [title] => Stone Angel
            [time] => 5:08
            [url] => http://m...content-available-to-author-only...o.net/getsong/76881833722168
            [rel] => 0.6
        )

    [15] => stdClass Object
        (
            [artist] => Justin Hurwitz
            [title] => City of Stars (Humming) [feat. Emma Stone]
            [time] => 2:43
            [url] => http://m...content-available-to-author-only...o.net/getsong/123005061947742
            [rel] => 0.6
        )

    [16] => stdClass Object
        (
            [artist] => Marcus Schossow & Reeves feat. Emma Hewitt
            [title] => Light (Stoneface & Terminal Vocal Remix)
            [time] => 6:57
            [url] => http://m...content-available-to-author-only...o.net/getsong/39661639124116
            [rel] => 0.6
        )

    [17] => stdClass Object
        (
            [artist] => Armin van Buuren
            [title] => Stone Cold [Asot Radio Classic]
            [time] => 6:04
            [url] => http://m...content-available-to-author-only...o.net/getsong/66306144887910
            [rel] => 0.6
        )

    [18] => stdClass Object
        (
            [artist] => Shogun feat. Emma Lock
            [title] => Save Me (Stoneface & Terminal vocal mix)
            [time] => 8:51
            [url] => http://m...content-available-to-author-only...o.net/getsong/48288951345578
            [rel] => 0.6
        )

    [19] => stdClass Object
        (
            [artist] => Shogun Feat. Emma Lock
            [title] => Save Me (Stoneface & Terminal Vocal Mix)
            [time] => 6:25
            [url] => http://m...content-available-to-author-only...o.net/getsong/122894434038111
            [rel] => 0.6
        )

    [20] => stdClass Object
        (
            [artist] => Heuse
            [title] => Stones (feat. Chris Linton & Emma Sameth)
            [time] => 2:55
            [url] => http://m...content-available-to-author-only...o.net/getsong/123006010822985
            [rel] => 0.6
        )

    [21] => stdClass Object
        (
            [artist] => Emma Deigman
            [title] => Tell Your Mama Stonebridge Club Remix
            [time] => 7:21
            [url] => http://m...content-available-to-author-only...o.net/getsong/73791306678772
            [rel] => 0.6
        )

    [22] => stdClass Object
        (
            [artist] => Emma Stone, Callie Hernandez, Sonoya Mizuno, Jessica Rothe
            [title] => Someone in the Crowd
            [time] => 4:19
            [url] => http://m...content-available-to-author-only...o.net/getsong/123005983252990
            [rel] => 0.6
        )

    [23] => stdClass Object
        (
            [artist] => Emma Stone/Ryan Gosling
            [title] => A Lovely Night
            [time] => 3:57
            [url] => http://m...content-available-to-author-only...o.net/getsong/123000854442439
            [rel] => 0.6
        )

    [24] => stdClass Object
        (
            [artist] => Lee Fields & The Expressions
            [title] => Stone Angel (Instrumental)
            [time] => 5:09
            [url] => http://m...content-available-to-author-only...o.net/getsong/122969125908759
            [rel] => 0.6
        )

    [25] => stdClass Object
        (
            [artist] => Cosmic Gate
            [title] => London Rain (Stoneface And Terminal Remix)
            [time] => 7:47
            [url] => http://m...content-available-to-author-only...o.net/getsong/122880090465350
            [rel] => 0.4
        )

    [26] => stdClass Object
        (
            [artist] => Cosmic Gate
            [title] => London Rain (Stoneface & Terminal Remix)
            [time] => 7:47
            [url] => http://m...content-available-to-author-only...o.net/getsong/39550523491444
            [rel] => 0.4
        )

    [27] => stdClass Object
        (
            [artist] => Cosmic Gate
            [title] => London Rain (Ruben De Ronde Remix)
            [time] => 3:08
            [url] => http://m...content-available-to-author-only...o.net/getsong/122880090461253
            [rel] => 0.4
        )

    [28] => stdClass Object
        (
            [artist] => Cosmic Gate
            [title] => Sometimes They Come Back for More (Stoneface & Terminal Remix)
            [time] => 7:42
            [url] => http://m...content-available-to-author-only...o.net/getsong/40093022577894
            [rel] => 0.4
        )

)