我喜欢在数组上执行搜索并在找到匹配项时返回所有值。数组中的键[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