theniteowl
Programmer
I have an array like this:
$nav[]=array('Home','home2','Teaching Teams','teams','Special Projects','projects','Student Activites','activities','After School Program','afterschool','News','news');
$nav[]=array('About Us','about','Contact Us','contact','Directions','directions','Student Handbook','handbook','Dress Guidelines','dresscode','Mission Statement','mission');
$nav[]=array('Resources','resources','Library','library','Health Office','health');
$nav[]=array('Staff','staff');
$nav[]=array('Grade Level','grade','Grade Six','grade6','Through Our Eyes','oureyes');
The array data is like this:
The first element in a row is text to display in the top level of the nav menu, the second element is the name of the folder it references. Each pair of elements thereafter represent the text/folder names for each option in the sub-menu.
I need to search through the array for a folder name not knowing if it will be a top or sub menu option and return it's position in the array.
I can evaluate the position to determine if it is top or sub menu easily enough but is there an easy way to search the array without setting up a double nested loop? I am an experienced programmer just not with PHP.
If there is a simple method of quickly searching the array for a string and returning it's position it would save me a lot of hassle.
If I have to use a double-nested loop then what is the best method to end the loop when a match is found rather than letting it search the rest of the way through?
If looping I am only testing odd number values as it is the folder rather than the text I am looking for.
The amount of data is small so the loop would not be long but I would like to write it correctly and efficiently up front.
I also know I could format the data easier for this particular type of search but the list has to be maintained by non-programmers and this format seemed the easiest for them to understand. At a later date I plan to write a GUI for them to maintain the nav list but it may be a while until I can get to that point.
Thanks.
At my age I still learn something new every day, but I forget two others.
$nav[]=array('Home','home2','Teaching Teams','teams','Special Projects','projects','Student Activites','activities','After School Program','afterschool','News','news');
$nav[]=array('About Us','about','Contact Us','contact','Directions','directions','Student Handbook','handbook','Dress Guidelines','dresscode','Mission Statement','mission');
$nav[]=array('Resources','resources','Library','library','Health Office','health');
$nav[]=array('Staff','staff');
$nav[]=array('Grade Level','grade','Grade Six','grade6','Through Our Eyes','oureyes');
The array data is like this:
The first element in a row is text to display in the top level of the nav menu, the second element is the name of the folder it references. Each pair of elements thereafter represent the text/folder names for each option in the sub-menu.
I need to search through the array for a folder name not knowing if it will be a top or sub menu option and return it's position in the array.
I can evaluate the position to determine if it is top or sub menu easily enough but is there an easy way to search the array without setting up a double nested loop? I am an experienced programmer just not with PHP.
If there is a simple method of quickly searching the array for a string and returning it's position it would save me a lot of hassle.
If I have to use a double-nested loop then what is the best method to end the loop when a match is found rather than letting it search the rest of the way through?
If looping I am only testing odd number values as it is the folder rather than the text I am looking for.
The amount of data is small so the loop would not be long but I would like to write it correctly and efficiently up front.
I also know I could format the data easier for this particular type of search but the list has to be maintained by non-programmers and this format seemed the easiest for them to understand. At a later date I plan to write a GUI for them to maintain the nav list but it may be a while until I can get to that point.
Thanks.
At my age I still learn something new every day, but I forget two others.