我有一個包含其他數組(子數組)的數組。我需要獲取包含特定鍵值的子數組的索引。例如。這是我的陣列:Php數組索引
Array
(
[0] => Array
(
[id] => 353
[name] => account_2
[ips] =>
[tech_prefix] =>
[password] =>
[id_voip_hosts] =>
[proxy_mode] =>
[auth_type] => ani
[ani] => 526466
[accname] =>
[protocol] =>
[port] =>
[orig_enabled] => 1
[term_enabled] =>
[orig_capacity] =>
[term_capacity] =>
[orig_rate_table] =>
[term_rate_table] =>
[id_dr_plans] =>
[orig_groups] =>
[term_groups] =>
[notes] =>
)
[1] => Array
(
[id] => 352
[name] => account_3
[ips] =>
[tech_prefix] =>
[password] =>
[id_voip_hosts] =>
[proxy_mode] =>
[auth_type] => ani
[ani] => 1345436
[accname] =>
[protocol] =>
[port] =>
[orig_enabled] => 1
[term_enabled] =>
[orig_capacity] =>
[term_capacity] =>
[orig_rate_table] =>
[term_rate_table] =>
[id_dr_plans] =>
[orig_groups] =>
[term_groups] =>
[notes] =>
)
[2] => Array
(
[id] => 354
[name] => account_4
[ips] =>
[tech_prefix] =>
[password] =>
[id_voip_hosts] =>
[proxy_mode] =>
[auth_type] => ani
[ani] => 472367427
[accname] =>
[protocol] =>
[port] =>
[orig_enabled] => 1
[term_enabled] =>
[orig_capacity] =>
[term_capacity] =>
[orig_rate_table] =>
[term_rate_table] =>
[id_dr_plans] =>
[orig_groups] =>
[term_groups] =>
[notes] =>
)
)
我需要什麼。例如,我需要從數組子數組[2]中刪除。我知道unset($ myarray [2])的一種方式,但我怎樣才能得到這個索引[2]。如果我只知道[ani]鍵值472367427.如何在var中獲取這個「[2]」以將其插入到未設置的命令中。 如果我需要刪除有一個密鑰[ani] = 1345436的子數組(它在數組[1]中)。有沒有辦法通過一個鍵的值來搜索數組的索引。 再次,如何通過[ani]鍵在多維數組中找到這個索引[2]或[1]? 謝謝!
以何種方式,你導航到每個[ANI]價值指數和
unset
元素?通過循環? –循環和'unset'或'array_filter'。這是非常基本的數組操作的東西,嘗試一些東西。 – deceze
有什麼我們失蹤的?你有什麼嘗試? – jterry