Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6959241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:14:44+00:00 2026-05-27T15:14:44+00:00

I have an array: $myArray=array( ‘hello my name is richard’, ‘hello my name is

  • 0

I have an array:

$myArray=array(

'hello my name is richard',
'hello my name is paul',
'hello my name is simon',
'hello it doesn\'t matter what my name is'

);

I need to find the sub string (min 2 words) that is repeated the most often, maybe in an array format, so my return array could look like this:

$return=array(

array('hello my', 3),
array('hello my name', 3),
array('hello my name is', 3),
array('my name', 4),
array('my name is', 4),
array('name is', 4),

);

So I can see from this array of arrays how often each string was repeated amongst all strings in the array.

Is the only way to do it like this?..

function repeatedSubStrings($array){

    foreach($array as $string){
        $phrases=//Split each string into maximum number of sub strings
        foreach($phrases as $phrase){
            //Then count the $phrases that are in the strings
        }
    }

}

I’ve tried a solution similar to the above but it was too slow, processing around 1000 rows per second, can anyone do it faster?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:14:45+00:00Added an answer on May 27, 2026 at 3:14 pm

    A solution to this might be

    function getHighestRecurrence($strs){
    
      /*Storage for individual words*/
      $words = Array();
    
      /*Process multiple strings*/
      if(is_array($strs))
          foreach($strs as $str)
             $words = array_merge($words, explode(" ", $str));
    
     /*Prepare single string*/
      else
          $words = explode(" ",$strs);
    
      /*Array for word counters*/
      $index = Array();
    
      /*Aggregate word counters*/
      foreach($words as $word)
    
              /*Increment count or create if it doesn't exist*/
              (isset($index[$word]))? $index[$word]++ : $index[$word] = 1;
    
    
      /*Sort array hy highest value and */
      arsort($index);
    
      /*Return the word*/
      return key($index);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array: myarr = []; I'm filling it with some values: myarray['name']
I have an array of numbers, for example, myarray = (45,3,56,7,21). What I need
I have this array: var myArray = [{'name': 'name1', 'desc': 'desc1'}, {'name':'name2', 'desc': 'desc2'},.....];
I have an integer array in an xml file as follows <integer-array name=myArray> <item>@drawable/pic1</item>
I have an array of JSON objects like so: var myArray = [ {name:'foo',number:2},
if I have an array like: var myArray = [ { 'color':'red', 'name': 'redName'
I have an array that is a member of a structure: $self->{myArray} = [value1,
I have a for loop that loops over one array... for i=1:length(myArray) In this
In PHP I can name my array indices so that I may have something
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.