find a string in an array
Posted: Tue Apr 26, 2005 5:47 am
what i am trying to do is to find an string1 in an array. the thing is that I need to only match part of the string that is in the array.
as you can see from the code the variable uri is also an array but I am looping through it and trying to see if it exists in the array linkList.
data should be as follows.
uri
Array ( [0] => [1] => services [2] => graphic [3] => web )
linkList
Array ( [0] => contact-menu [1] => graphic-design-submenu [2] => services-menu )
for example find graphic (uri[2]) in linklist (linkList[1]) and return the index of linkList.
I know I could do it with a couple of for or while loops but was wondering if there is an easier way.
And yes, I know that my for loop counts down instead of up becuase of the way that I will have to display the data.
Thanks
phpScott
as you can see from the code the variable uri is also an array but I am looping through it and trying to see if it exists in the array linkList.
data should be as follows.
uri
Array ( [0] => [1] => services [2] => graphic [3] => web )
linkList
Array ( [0] => contact-menu [1] => graphic-design-submenu [2] => services-menu )
for example find graphic (uri[2]) in linklist (linkList[1]) and return the index of linkList.
I know I could do it with a couple of for or while loops but was wondering if there is an easier way.
And yes, I know that my for loop counts down instead of up becuase of the way that I will have to display the data.
Code: Select all
function createExplode()
{
global $linkList;
$uri= explode("/", $_SERVER['REQUEST_URI']);
$x = count($uri);
for($y = $x; $y > 0; $y--)
{
$temp = $uri[$y-1];
if($num = strstr($temp, array_search($temp, $linkList)))
{
echo ($linkList[$num]);
}
else
{
echo "not found<br />";
}
}
}phpScott