poe Posted March 20, 2008 Share Posted March 20, 2008 if i have an array like so: $sptAry = array( 'hockey' => array( 'olg'=>'hky', 'si'=>'nhl', ), 'baseball' => array( 'olg'=>'bbl', 'si'=>'mlb', ), ); and i have $olgsport = 'hky' how do i get the 'si' equivilent which is 'nhl' thanks chris Link to comment https://forums.phpfreaks.com/topic/97115-search-in-array/ Share on other sites More sharing options...
rhodesa Posted March 20, 2008 Share Posted March 20, 2008 this is one way: <?php function get_si ( $array, $olg ) { foreach($sptAry $keys){ if($keys['olg'] == $olg) return $keys['si']; } return false; } $sptAry = array( 'hockey' => array( 'olg'=>'hky', 'si'=>'nhl', ), 'baseball' => array( 'olg'=>'bbl', 'si'=>'mlb', ), ); print get_si($sptAry,'hky'); ?> Link to comment https://forums.phpfreaks.com/topic/97115-search-in-array/#findComment-496949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.