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
ClintonKAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vel EousResearch & Development ManagerCommented:
You can reset the array pointer (moving you back to the start) and then loop through your array using next to compare the current iteration key with your base key.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ClintonKAuthor Commented:
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

0
ClintonKAuthor Commented:
Advice successfully coded and included in the project.
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.