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 7648259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:40:17+00:00 2026-05-31T10:40:17+00:00

I’ve got this 2 variables that I want to compare on a certain way.

  • 0

I’ve got this 2 variables that I want to compare on a certain way. So I already figured out that I have to put it in a array and compare them that way. But there’s the problem.

If my input is ‘rieebbb’, random sequence.
And my other input is ‘beer’ as in, the word beer.

How do I check if the letters in beer are all in ‘rieebbb’ and that I all use them once?
So ‘riebbb’ shouldn’t give a positive answer because I am missing a ‘e’ in the random sequence.

I’ve already tried array_intersect() but that did’nt totaly work because it didn’t check for letters already used in array 1.

  • 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-31T10:40:18+00:00Added an answer on May 31, 2026 at 10:40 am

    Do a frequency match..count the occurrence of each character in say “beer” and store that in an array A.

    That would be {{b,1},{e,2},{r,1})..

    Do the same on your target string.

    Compare the two arrays for the letters in the array A.
    That should solve it.

    Here’s the code for the same:

    <?php
    $data = "beer";
    
    $data2="rebe";
    $p=0;
    $q=0;
    $stat=0;
    foreach (count_chars($data, 1) as $i => $val)   
    {
      $arr1[$p][0]=chr($i);
      $arr1[$p][1]=$val;
      $p=$p+1;
    }
    foreach (count_chars($data2, 1) as $j => $val2) 
    {
        $arr2[$q][0]=chr($j);
        $arr2[$q][1]=$val2;     
        $q=$q+1;
    }
    
    for($st=0;$st<$q;$st=$st+1)
    {
            for($sp=0;$sp<$p;$sp=$sp+1)
            {
                if($arr2[$st][0]==$arr1[$sp][0])
                {
                        if($arr2[$st][1]<$arr1[$sp][1])
                        {
                                $stat=1;
                        }
                }
        }
    }
    if($stat==0)
    {
    echo "They match";
    }
         else
    {
     echo "They dont match";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.