Jump to content

Accessing array with variable?


gsmith

Recommended Posts

I thought I knew how to do this, but things aren't working. I'm trying to reference a certain value in an array, without knowing ahead of time the exact key. So I've got:

$usersname=$_POST["username"];//Find the array pointer for this user$c=1;foreach ($uname as $value)    {      if ($usersname != $value)        {          $c++;        }      else        {          break;        }    }print_r($uname[$c]);

But it won't print anything at the end! If I hardcode in a value for $c in the print_r statement (put a 2 in there for instance) it works...but it won't work with $c! Any help please?

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