2012-11-16 94 views
1

我有一個數組:比較multidimsensional數組值

array (
    [0] => Array (
     [host] => google.nl 
     [class] => IN 
     [ttl] => 279310 
     [type] => NS 
     [target] => ns3.google.com) 
    [1] => Array (
     [host] => google.nl 
     [class] => IN 
     [ttl] => 279310 
     [type] => NS 
     [target] => ns4.google.com) 
    [2] => Array (
     [host] => google.nl 
     [class] => IN 
     [ttl] => 279310 
     [type] => NS 
     [target] => ns2.google.com) 

這個陣列與dns_get_record()功能製成。這是每個域的不同數量的變量。 如何將[0]['target'][1]['target'][2]['target']進行比較,並且如果剩餘目標的數量更多?

回答

0

我不確定這段代碼寫了什麼語言,這是一個在C#\ Java中解決這個問題的例子,當然還有很多其他的方法。

使用一個簡單的for循環,意思是:如果大數組的名稱是「mainArray」,你需要做的:

foreach (int i=0;i<mainArray.length();i++) 
{ 
    if !(mainArray[i]["target"].Equals(mainArray[i+1]["target"])) 
     return false; 
} 
return true;