Getting keys and values of an array and Assigning it to another array in PHP. (newbie here) Need Suggestions
<p>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.</p>

<p>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. </p>

<p>Do you guys have any ideas about this? Suggestions please?</p>

<p>Here are the codes:</p>

<pre><code>&lt;?php
    class GreekNum
    {           
        public function setText($text)
        {
            $this-&gt;text=$text;
        }

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

        public function Convert($text)
        {

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

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

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

            }                   
        }

    }   

    $GreekNum = new GreekNum();

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

    echo "&lt;br&gt;";
    echo "&lt;b&gt;Entered Values: &lt;/b&gt;&lt;br&gt;". $GreekNum-&gt;getText();
    echo "&lt;br&gt;";
    echo "&lt;br&gt;";

    echo "&lt;b&gt;Decimal Number Equivalence: &lt;/b&gt;&lt;br/&gt;". $GreekNum-&gt;Convert($text);



?&gt;
</code></pre>

<p>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.</p>
