我喜歡在數組上執行搜索並在找到匹配項時返回所有值。數組中的鍵[name]
就是我正在搜索的內容。當發現匹配時搜索數組並返回所有鍵和值
Array (
[0] => Array
(
[id] => 20120100
[link] => www.janedoe.com
[name] => Jane Doe
)
[1] => Array
(
[id] => 20120101
[link] => www.johndoe.com
[name] => John Doe
)
)
如果我做了李四搜索將返回。
Array
(
[id] => 20120101
[link] => www.johndoe.com
[name] => John Doe
)
根據我正在搜索的內容重命名數組會更容易嗎?而不是上面的數組,我也可以生成以下內容。
Array (
[Jane Doe] => Array
(
[id] => 20120100
[link] => www.janedoe.com
[name] => Jane Doe
)
[John Doe] => Array
(
[id] => 20120101
[link] => www.johndoe.com
[name] => John Doe
)
)
你冒重複鍵的機會,如果你使用的名稱爲你的鑰匙。 – BenOfTheNorth 2012-02-25 00:21:33
比我會忽略第二個想法,並只搜索第一個數組。 – Tim 2012-02-25 00:26:26