Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Pointer to variable as a variable

Is there a way in PHP to setup a pointer to another variable, change it which changes the initial variable?

So, for example:-
$arr[6]['cnt'] = 0;
$currentPointer = $arr[6]['cnt'];
$currentPointer++;

//Should echo out 1
echo $arr[6]['cnt'];

Open in new window

I know my code doesn't work, and I know its wrong, but I have no idea how pointers work in PHP, or if its even possible.

Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

You need an ampersand (&).
$arr[6]['cnt'] = 0;
$currentPointer = &$arr[6]['cnt'];
$currentPointer++;

//Should echo out 1
echo $arr[6]['cnt'];

Open in new window