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? Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/ 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)) Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326285 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 Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326297 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. Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326300 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++; } ?> Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326314 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 Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326328 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"; ?> Link to comment https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.