plutomed Posted August 17, 2007 Share Posted August 17, 2007 I have my array and I have just selected a key outta that array with array_keys(); and I got a key returned now how do I search another array for that key? Quote Link to comment Share on other sites More sharing options...
btherl Posted August 17, 2007 Share Posted August 17, 2007 To search for that key as a value: if (in_array($key, $array)) To search for that key as a key: if (array_key_exists($key, $array)) Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 17, 2007 Author Share Posted August 17, 2007 I'm just getting 1 returned and I don't wanna search for it I just wanna select from another array where a key = another key Quote Link to comment Share on other sites More sharing options...
btherl Posted August 17, 2007 Share Posted August 17, 2007 Can you show the code you have so far, and give a clearer explanation of what you want to do? An example would be great. Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 17, 2007 Author Share Posted August 17, 2007 the array: <?php $main_nav = array( "names" => array("Home", "Pictures", "Templates", "Website Coding"), "pages" => array("index.php", "pictures.php", "templates.php", "website_coding.php") ); ?> the breadcrub code I am going throught making: <?php $page = $_SERVER['PHP_SELF']; $explode = explode("/", $page); $counted = count($explode); $i_i = 0; while($i_i < $counted) { if($i_i == $counted-1) { $sub_nav_data = sub_nav(); $main_nav = main_nav(); $search = array_keys($main_nav['pages'], $explode[$i_i]); //the line below is the one $search2 = in_array($search[0], $main_nav['names']); //the line above echo "<a href=\"".$explode[$i_i]."\">".$search2."</a>"; } $i_i++; } ?> Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 17, 2007 Author Share Posted August 17, 2007 Could anyone help coz I'm off to bed soon Quote Link to comment Share on other sites More sharing options...
btherl Posted August 17, 2007 Share Posted August 17, 2007 I think you want array_search() .. eg <?php $main_nav = array( "names" => array("Home", "Pictures", "Templates", "Website Coding"), "pages" => array("index.php", "pictures.php", "templates.php", "website_coding.php") ); $find = 'Templates'; $index = array_search($find, $main_nav['names']); print "$find uses the script {$main_nav['pages'][$index]}\n"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.