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

  • SEARCH
  • Home
  • 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 7679795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:57:41+00:00 2026-05-31T17:57:41+00:00

I have an array of strings of random letters, and I need to know

  • 0

I have an array of strings of random letters, and I need to know which letters are consistent between the array members. The count of the letters are important.

My method right now is loop through the array, doing a split, then looping through the spitted string to count the occurrences of each letter, then update the array with letter => count

Then do an array_reduce that creates a new array of members who only occur in all arrays. But, it’s not working.

<?
$a[] = "emaijuqqrauw";
$a[] = "aaeggimqruuz";
$a[] = "aabimqrtuuzw";
$a[] = "aacikmqruuxz";
$a[] = "aacikmqruuxz";
$a[] = "aaciimqruuxy";

foreach($a as $b){
    $n = str_split($b, 1);
    foreach($n as $z){
        $arr[$z] = substr_count($b, $z);
    }
    ksort($arr);
    $array[] = $arr;
    unset($arr);
}

$n = array_reduce($array, function($result, $item){
    if($result === null){
        return $item;
    }else{
        foreach($item as $key => $val){
            if(isset($result[$key])){
                $new[$key] = $val;
            }
        }
        return $new;
    }
});

foreach($n as $key => $val){
    echo str_repeat($key, $val);
}

This returns aaiimqruu – which is kinda right, but there’s only 2 i‘s in the last element of the array. There’s only one i in the rest. I’m not sure how to break that down farther and get it to return aaimqruu– which I’ll then pop into a SQL query to find a matching word, aquarium

  • 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-31T17:57:42+00:00Added an answer on May 31, 2026 at 5:57 pm

    Seems like array_reduce is the best function for what this purpose, however I just didn’t think of adding a conditional to give me the desired effect.

    $new[$key] = ($result[$key] > $val) ? $val : $result[$key];
    

    to replace

    $new[$key] = $val;
    

    did the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have a function which takes a 2D array and generates random
Currently, I have an array of Strings, each with random characters in it that
Possible Duplicate: PHP: Filter array I have a PHP array containing strings of random
I have random strings that are similar to this: 2d4hk8x37m or whatever. I need
Possible Duplicate: Non repeating random number array I have a String array with many
So, I have a string array of some random saying and the like, but
I have array of strings, String[] data and it's 10 elements has value P
I have an array of strings var controlsToGet = new[] {lblHome,lblContact}; I have List<LanguageControl>
I have an array of strings. How can I convert it to System.Collections.ArrayList?
I have an array of strings that I want to use for button titles

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.