Avatar of ClintonK
ClintonK
Flag for United Kingdom of Great Britain and Northern Ireland asked on

How to set array pointer to a specific position?

Is there a way to set the pointer of an array to a specific key?
I save the current position in an array using
$base_position = key($myarray);

Open in new window

I then do various reads back and forth in the array using
prev($myarray);

Open in new window

and
next($myarray);

Open in new window

at the end of the routine I want to be able to go back to my base position in the array using the key that I saved in $base_position
PHP

Avatar of undefined
Last Comment
ClintonK

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Vel Eous

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ClintonK

ASKER
From Vel Eous's advice I use this code to locate he current key and then move the array pointer
/
* find out where the current type is in the array. Read through the array until $var is found*/
foreach ($aircraft_types as $key => $info):
	if (array_search($var, $info)): break; endif;
endforeach;
				
/* move the array pointer to the location of the current type */
reset($aircraft_types);
while (key($aircraft_types) !== $key && key($aircraft_types) !== null) next($aircraft_types);

Open in new window

ClintonK

ASKER
Advice successfully coded and included in the project.
Thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck