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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:02:39+00:00 2026-05-11T17:02:39+00:00

Suggestions for an updated title are welcome, as I’m having trouble easily quantifying what

  • 0

Suggestions for an updated title are welcome, as I’m having trouble easily quantifying what I’m trying to do.

This is a web-based form with PHP doing the calculations, though this question probably has an algorithmic or language agnostic answer.

Essentially, there is an Amount field and a Charge Code field.
The Charge code entered represents a short-hand for several ‘agents’ to whom the Amount is divided by. Most cases are single letters, however there are a couple cases where this varies, and gives a bit of trouble.

Basically, A = AgentType1, J = AgentType2, L = AgentType3, and as paperwork and user requirements would have it, “A2” is also a valid replacement for “J”.

So an amount of 50 and a Charge Code of “AJ” would result in the Amount being divided by 2 (two agents) and dispersed accordingly. The same for a string like “AA2”.

I have currently set up process (that works) that goes like this:

Divide = 0;
RegEx check for AgentType1 in Charge Code: 
 Divide++;
 Set This-AgentType-Gets-Return; 
RegEx check for AgentType2 in Charge Code: 
 Devide++;
 Set This-AgentType-Gets-Return;
... etc ...

Then I divide the Amount by the “Divide” amount, and the result gets divvied up to each AgentType present in the Charge Code.

I know there must be an easier/simpler way to implement this, but it’s not coming to me at the moment.

Is there a way to quickly derive the number of AgentTypes involved in the Charge Code, and which they are?

  • 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-11T17:02:39+00:00Added an answer on May 11, 2026 at 5:02 pm

    I would probably just do something simple like this:

    $valid_codes = array('A', 'J', 'L');
    
    // deal with the special A2 case first, to get it out of the string
    // this code could be generalized if more special cases need to be handled
    if (stripos($charge_code, 'A2') !== FALSE)
    {
        $found['J'] = true;
        str_ireplace('A2', '', $charge_code);
    }
    
    foreach ($valid_codes as $code)
    {
        if (stripos($charge_code, $code) !== FALSE) // if the code was in the string
        {
            $found[$code] = true;
        }
    }
    

    Now you can get the number you need to divide amount by with count($found), and the codes you need to divide between with array_keys($found).

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

Sidebar

Related Questions

EDIT: Updated with suggestions from Bill Karwin below. Still very slow. I'm trying to
Any suggestions for an accurate Web Log analysis tool to generate reports on the
I think that (the title) is the problem I am having. I set up
The title pretty much explains it. I'm having an odd situation where views that
What I'm trying to do here is to create a list of groups based
I am having an array like author,post title,date,time,post category, etc etc I scrape the
i've been struggling with this problem for quite some time. I've followed all suggestions
As the title suggests, is this test name just a little of the top?
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
I am looking for a simple JavaScript example that updates DOM. Any suggestions?

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.