Selacius Posted December 15, 2005 Share Posted December 15, 2005 On a webpage I have an array which is filled with variables such as: $wprearray = array ("$wcomment","$wcgd", "$wcmf", "$wcmp"); Now these variables are defined elsewhere in the page so when they are placed into the array they will contain a value. With this array I will then add to the values already placed inside. EG. $wprearray[2] = $wprearray[2] + 5;Now if $wprearray[2] had an original value of 2, then after this it should have a value of 7. But that is not the case. The final value is displayed as 5. What is wrong here? Link to comment Share on other sites More sharing options...
Jack McKalling Posted December 16, 2005 Share Posted December 16, 2005 Maybe it read the value as a string, which can't be counted :)You could use settype($wprearray[2], "integer") to make it a number Link to comment Share on other sites More sharing options...
Selacius Posted December 22, 2005 Author Share Posted December 22, 2005 Figured out the problem with this. When adding values to an array and trying to display the values on a page, start at 0. For example:$array = array(1,2,3,4,5,6);echo $array[1]; //Shows up as 2echo $array[0]; //Shows up as 1 Link to comment Share on other sites More sharing options...
Jack McKalling Posted December 22, 2005 Share Posted December 22, 2005 Whaha we should have known :)Very - not to be embarassed - common mistake Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now