Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Array Questions

  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    Array Questions

    I need some array manipulation help.

    I have two arrays ($array_headlineKeywords and $array_bodyKeywords), for example:

    Array ( [0] => [1] => yahoo [2] => eyeing [3] => online [4] => music [5] => service [6] => )


    Array ( [0] => [1] => yahoo [2] => discussions [3] => major [4] => record [5] => labels [6] => offering [7] => unprotected [8] => mp3s [9] => sale [10] => free [11] => part [12] => ad-supported [13] => service [14] => record [15] => company [16] => executives [17] => familiar [18] => talks [19] => wednesday [20] => )


    I want to combine both arrays into 1 array (say $array_headlinebodyKeywords)

    and then count the frequency of each word (I assume array_count_values can do that)

    and then arrange each element in the array in the order of greatest frequency to least frequency

    and then only keep the first 5 elements in the array (which are the most frequently appearing words in the array)

    ---
    anyone know how to do this?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    $result array_count_values(array_merge($array_headlineKeywords$array_bodyKeywords);
    asort($result);
    $array_headlinebodyKeywords array_split(array_reverse($result),0,5); 
    arrays everywhere. :

    http://www.php.net/manual/en/ref.array.php

    best regards
    Last edited by oesxyl; 01-24-2008 at 03:28 AM.

  • Users who have thanked oesxyl for this post:

    Bobafart (01-24-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •