2011-06-16 67 views
-2

對於任何真正想要挑戰的人! :)PHP:查找數組索引號?

我怎麼會去使用一個字符串,如Wonder Bingo = 0

array(4) { 
    ["eirepanel_inline_ads_options_saved"]=> 
    string(4) "true" 
    ["eirepanel_inline_ads_options_name"]=> 
    array(2) { 
    [0]=> 
    string(12) "Wonder Bingo" 
    [1]=> 
    string(10) "City Bingo" 
    } 
    ["eirepanel_inline_ads_options_affiliate_link"]=> 
    array(2) { 
    [0]=> 
    string(20) "/visit/wonder_bingo/" 
    [1]=> 
    string(17) "/visit/city_bingo" 
    } 
    ["eirepanel_inline_ads_options_thumbnail"]=> 
    array(2) { 
    [0]=> 
    string(45) "http://www.freenodepositbingo.co.uk/image.png" 
    [1]=> 
    string(46) "http://www.freenodepositbingo.co.uk/image2.png" 
    } 
} 
+0

是什麼'神奇賓果= 0'是什麼意思?字符串「Wonder Bingo」應該在你搜索的鍵值的'0'索引處?另外,你有沒有嘗試過什麼? – deceze 2011-06-16 04:08:12

回答

0
$str = preg_replace('/ = \d+$/', '', 'Wonder Bingo = 0'); 

$key = array_search($str, $array['eirepanel_inline_ads_options_name']); 
0

對不起球員找到的eirepanel_inline_ads_options_name指數,只是理解了它。

echo $key = array_search('WonderBingo', $eirepanel_inline_ads_options['eirepanel_inline_ads_options_name']); 
0

解釋要求Wonder Bingo = 0意義0索引的搜索關鍵字等於"Wonder Bingo"

function find($needle, $haystack) { 
    preg_match('/^(.+) = (\d+)$/', $needle, $matches); 
    foreach ($haystack as $key => $value) { 
     if (isset($value[$matches[2]]) && $value[$matches[2]] == $matches[1]) { 
      return $key; 
     } 
    } 
}