Jump to content

Variables In Array?


Selacius

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...