How do I calculate array values?

Hi all

First time posting.

I am having problems adding the values from a Multidimensional array and I am really lost for why it is not working.

I have a script that scraps a website and pulls into an array the name of sports players and the current amount of points they have earned so far this season.

Of the 300 odd names it finds I am only interested in 11 of those players. I am able to pull out any of that data and display it on the screen. I can even pass that data to any other string I create.

However, when I try and add the values it does not work and simply returns 0 no matter what I do.

Here is some of the code I am using in the hope someone might be able to tell me how to do it.

echo $articles[33][2]." - “.$articles[33][3].” - “.$articles[33][6];
echo $articles[65][2].” - “.$articles[65][3].” - ".$articles[65][6];

The above two lines will display the players name, team and points earned so far.

What I want to do is add the values from $articles[33][6] with $articles[65][6] but no matter what I do it just displays nothing or a zero.

for example…

$articles[33][6] has the value of “27”
$articles[65][6] has the value of “13”

echo $articles[33][6] + $articles[65][6];

This should display 40 but instead it displays 0

Any help would be appreciated.

Try trimming the values in your addition:

[php]echo (trim($articles[33][6]) + trim($articles[65][6]));[/php]

Thanks for the reply.

I did eventually solve it by fluke. What I didn’t know was the values that I had scrapped also included the HTML code so where as I thought the variable just had a number it was actually. It makes sense why when I would echo the result to the screen I just saw the number.

37

Once I used strip_tags($articles[33][6]) it worked and I was able to calculate with the numbers.

Sponsor our Newsletter | Privacy Policy | Terms of Service