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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:55:38+00:00 2026-06-08T06:55:38+00:00

I am looking for a way to extract/get values from an array and assign

  • 0

I am looking for a way to extract/get values from an array and assign the values to a variable and get the sum of all values.

To be more specific, the user will be entering a certain group of letters. The letters that will be entered will be compared to the keys of an existing array if there are matches or not. When there are matches in the array, the corresponding values of the keys(that have matches) will be assigned to a new variable, and the sum of the values (w/c are expected to be numeric) will be calculated. I have been trying to find a way for this, but due to inexperience, I have not really found a good way.

Do you guys have any ideas about this? Suggestions please?

Here are the codes:

<?php
    class GreekNum
    {           
        public function setText($text)
        {
            $this->text=$text;
        }

        public function getText()
        {
            return $this->text;
        }       

        public function Convert($text)
        {

            $TextLength = strlen($text);
            $text = strtoupper($text);
            $text = str_split($text);       

            $collection = array(
                                    "A" => 1,
                                    "B" => 2,
                                    "G" => 3,
                                    "D" => 4,
                                    "E" => 5,
                                    "#" => 6,
                                    "Z" => 7,
                                    "Y" => 8,
                                    "H" => 9,
                                    "I" => 10,
                                    "K" => 20,
                                    "4" => 30,
                                    "M" => 40,
                                    "N" => 50,
                                    "X" => 60,
                                    "O" => 70,
                                    "P" => 80,
                                    "Q" => 90,
                                    "R" => 100,
                                    "S" => 200,
                                    "T" => 300,
                                    "U" => 400,
                                    "F" => 500, 
                                    "C" => 600,             
                                    "$" => 700,
                                    "W" => 800,
                                    "3" => 900, 
                                );

            if(isset($text))
            {
                $total = 0;
                for($i=0; $i<$TextLength; $i++)
                {
                    if(array_key_exists($text[$i], $collection))
                    {
                        $total += $text[$i];
                    }
                }
                return $total;

            }                   
        }

    }   

    $GreekNum = new GreekNum();

    $text = $_POST['text'];
    $GreekNum->setText($text);

    echo "<br>";
    echo "<b>Entered Values: </b><br>". $GreekNum->getText();
    echo "<br>";
    echo "<br>";

    echo "<b>Decimal Number Equivalence: </b><br/>". $GreekNum->Convert($text);



?>

To the guys who have seen these codes, yes, I have posted it because there was an error that I cant seem to find. I was able to fix the error but the issue now is that I can’t really get the output that I need. Please do understand. Thanks.

  • 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-06-08T06:55:39+00:00Added an answer on June 8, 2026 at 6:55 am

    If you are seeking to get the sum of the values for each letter entered, then replace this :

    $total += $text[$i];
    

    By this :

    $total += $collection[$text[$i]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to get all the information out of localStorage. The
I'm looking for a way to extract info on all branches within a repository.
I am looking for a way to automatically extract parts from audio files. Something
I'm looking for a way to extract text from a pdf and use it
I'm looking for a way to get all table creation and alteration queries attached
I am looking for a way to extract / scrape data from Word files
All I'm looking for is a way to get the current drive letter that
I'm looking for a clever way to extract 500 plus lines of data from
Looking for a way to get path of file (and then process it in
Looking for a way to get the seconds until @post.created_at date time with timezone.

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.