我有一個方法,fetch_widgets
,從(MySQL)數據庫中獲取小部件。我將它傳遞一個$options
陣列所以可以有選擇地添加WHERE
和JOIN
子句,添加/刪除列等PHP數組:索引與鍵控
例如:
$options = array();
$options[] = 'include_disabled';
$options[] = 'include_tag_ids';
$options['start_date'] = '2011-01-01';
$options['end_date'] = '2011-01-31';
在fetch_widgets
我使用檢查的選項之一:
if(array_key_exists('start_date',$options)) { ... }
或:
if(in_array('include_tag_ids',$options)) { ... }
取決於該選項是否被激活而僅存在(例如, include_disabled
)或具有密鑰和值(例如end_date
)。
我遇到了困難,因爲in_array
當$options
數組包含鍵值和非鍵值時,我得到了奇怪的結果。任何人都可以對此有所瞭解嗎?
什麼是你所得到的奇怪的行爲? – 2011-05-23 19:53:33
鑑於上述'$ options'數組我有'in_array('include_tag_ids',$ options)'return false。我似乎已經解決了它,不知道我改變了什麼,但它再次工作 – Matthew 2011-05-23 21:21:03