2017-07-18 22 views
-2
Array ( 
    [01755677011] => Array ( 

     [0] => Array ( 

      [0] => 1 
      [id] => 1 
      [1] => 01755677011 
      [phone_num] => 01755677011 
      [2] => NoAnswer 
      [status] => Answer 
     ) 
     [1] => Array ( 

      [0] => 2 
      [id] => 2 
      [1] => 01755677011 
      [phone_num] => 01755677011 
      [2] => NoAnswer 
      [status] => NoAnswer 
     ) 
     [2] => Array ( 

      [0] => 3 
      [id] => 3 
      [1] => 01755677011 
      [phone_num] => 01755677011 
      [2] => Answer 
      [status] => NoAnswer 
     ) 
     [3] => Array ( 

      [0] => 4 
      [id] => 4 
      [1] => 01755677011 
      [phone_num] => 01755677011 
      [2] => Answer 
      [status] => Answer 
     ) 
    ) 
    [01755677012] => Array (

     [0] => Array ( 

      [0] => 16 
      [id] => 16 
      [1] => 01755677012 
      [phone_num] => 01755677012 
      [2] =>No Answer 
      [status] => NoAnswer 
     ) 
     [1] => Array ( 

      [0] => 18 
      [id] => 18 
      [1] => 01755677012 
      [phone_num] => 01755677012 
      [2] => Answer 
      [status] => Answer 
     ) 
    ) 
) 

這是我當前的數組。我只想過濾phone_num的應答狀態。
Outpout會喜歡這個:PHP - 給定值的多維數組過濾

Phone Num No of answer 
01755677011 0,23 
01755677012 1 

誰能HELO我請?

+1

如何在所需的輸出中得到答案列值?我沒有看到你的輸入數組中的任何類型的值 –

+0

$ qry_num_fetch =「SELECT * FROM phnno_tbl」; \t \t $ exc_qry = mysqli_query($ conn,$ qry_num_fetch); \t \t而($行= mysqli_fetch_array($ exc_qry)) \t \t { \t \t \t $ num個[] = $行; \t \t \t} \t \t \t \t $ \t結果=陣列(); \t \t foreach($ num as $ element){ \t \t \t $ result [$ element ['phone_num']] [] = $ element; \t \t \t $ res [$ element ['phone_num']] = $ element; \t \t \t \t} \t \t 的foreach \t($ RES作爲$密鑰=> $值) \t \t { \t \t \t $數[] = $密鑰; \t \t \t \t \t \t } \t \t \t \t // \t的print_r($結果[$數] [0] [ '狀態']); \t \t print_r($ result); 其實它是我的查詢結果數據。我想通過Answer來過濾這個數組,最後通過電話號碼輸出Answer組的鍵。 –

+0

我還是不明白你如何得到「答案否」的值,它是「狀態」=答案/否答案的函數? –

回答

0

我不明白你怎麼弄0,23爲01755677011.如果要顯示PHONE_NUM和時代其編號爲「接聽」狀態,可以這樣來做:

$result = array(); 
foreach ($num as $key => $row) { 
    $result[$key] = array(); 
    $count = 0; 
    foreach($row as $key_value => $row_value) { 
     if ($row_value['status'] == 'Answer') { 
      // $key is the key 01755677011 and 01755677012 
      $result[$key]['id'][$count] = $row_value['id']; 
      $count++; 
     } 
    } 
} 

if (!empty($result)) { 
    echo "Phone Num | No of answer<br />"; 
    foreach ($result as $key => $row) { 
     echo $key . " " . count($row['id']) . "<br />";   
    } 
} 

第二個版本:

1)根據[狀態]或[2]中的「答案」。

2)顯示相應phone_num的數組索引。

$result = array(); 
foreach ($num as $key => $row) { 
    $result[$key] = array(); 
    $count = 0; 
    foreach($row as $key_value => $row_value) { 
     if ($row_value['2'] == 'Answer' || $row_value['status'] == 'Answer') { 
      // $key is the key 01755677011 and 01755677012 
      $result[$key][$count]['index'] = $key_value; 
      $count++; 
     } 
    } 
} 

print_r($result); 

if (!empty($result)) { 
    echo "Phone Num | No of answer<br />"; 
    foreach ($result as $key => $row) { 
     echo $key . " | "; 
     if (!empty($row)) { 
      foreach ($row as $data_key => $data) { 
       echo $data['index']; 
      } 
     } else { 
      echo "No record"; 
     } 
     echo "<br />"; 
    } 
} 
+0

其實我想要的是關於電話號碼的回答時間。如果我們看到陣列,我們可以看到01755677011 - 總共的回答時間是3.首先0沒有鑰匙然後2沒有鑰匙和最後3沒有鑰匙。這意味着這(01755677011)已經第一次,然後第三次,然後第四次回答。所以最後我想得到結果,有多少次被回答,以及在Noanswer之後回答的時間。 只需要我想要的關鍵電話號碼答案。 –

+0

我還是不明白。有4次嘗試01755677011.我沒有看到3來自哪裏。除非您正在查看數組索引,如[01755677011] [0],[01755677011] [2],[01755677011] [3]? – louisecode

+0

而且當你說「已回答」時,它是指[狀態]還是「[2] =>回答」? – louisecode