2013-07-09 69 views
-1

從數組中刪除子陣列我有一個陣列:PHP由值

Array 




( 
    [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] => 
) 
[3] => Array 
( 
[auth_type] => ani 
[name] => 472367427 
[ani] => 472367427 
[orig_enabled] => Array 
( 
[0] => on 
) 
) 
)` 

的主陣列coult含有許多「子陣列」,從[1]〜[10]例如。 我需要什麼:我需要刪除「子陣列」女巫有[任何] => $ todel 例如,$ todel = 472367427,這意味着該數組必須包含子數組[1]和[3]等等。

+3

你有關於如何解決這個問題有什麼想法? – zerkms

+0

472367427值是如何表示必須包含子數組[1]和[3]?另外,我仍然不確定你想要實現什麼... –

+0

哦,請縮進你的代碼。 –

回答

0

這很容易與unset

$yourIndex = 2; 
unset($yourArray[$yourIndex]); // this will remove the third element, index: 2 

隨着unset數組索引將保持不變,所以如果你想重新轉移指標,使用array_splice功能如下:

$yourIndex = 2; 
array_splice($yourArray, $yourIndex, 1); // "1" in the last argument indicates how many elements will be removed starting from the $yourIndex value 

更多上:

+0

以及如何獲取索引由ani? – user2563906

+0

@ user2563906 - 什麼是「ani」?這是一個如何移除數組中包含的任何元素的示例。您可以使用此片段來了解如何從數組中移除單個元素。 – 2013-07-09 09:45:36

+0

$您的索引= 2; unset($ yourArray [$ yourIndex]);正在工作,但第二個問題。 ,$ mainarray);它會在array [0] array [1]中搜索等等? – user2563906