2017-06-25 51 views
0

我有一個數組,我需要打印如果電話號碼與字符串匹配,並顯示基於該數字的名字?我必須打印與名稱相應的數字。如何實現這一點如何根據與php中的數組匹配的結果得到結果?

$phone_number = 8056006655; 

    Array ([0] => Array ([phone] => 8056006655 [country_code] => +91 [status] => [email] => [email protected]ldamanifoundations.com [call_groups] => Array () [role] => [wrap_up_times] => Array () [first_name] => Dominic [id] => 850688 [opt_in] => 1 [last_name] =>) 
+0

什麼是PHP版本?使用5.6 – Doug

+0

@Doug IM($ get_agent_array [ '對象']作爲$鍵=> $值){ \t \t \t \t \t \t \t \t \t \t \t \t \t $ agent_phone_number [ 'PHONE_NUMBER'] = $值['電話']; \t \t \t \t $ agent_first_name ['first_name'] = $ value ['first_name']; \t \t \t \t \t \t \t \t //的print_r(array_merge($ agent_phone_number [ 'PHONE_NUMBER'],$ agent_first_name [ '如first_name'])); \t \t \t \t \t \t \t //回波$ get_agent_array [ '對象'] [$鍵] [ '電話']; \t \t \t \t \t // print_r($ agent_phone_number ['phone_number']); \t \t \t \t} –

+0

的foreach –

回答

0

你正在尋找它的array_column內的array_search,在php之前。 5.5你需要一個醜陋的foreach,然而從5.5你可以使用類似下面的東西。

$phone_number = 8056006655; 

$array = array(
    [0] => Array (
     [phone] => 8056006655 
     [country_code] => +91 
     [status] => 
     [email] => [email protected] 
     [call_groups] => Array () 
     [role] => 
     [wrap_up_times] => Array () 
     [first_name] => Dominic 
     [id] => 850688 
     [opt_in] => 1 
     [last_name] => 
     ) 
); 


$key = array_search($phone_number,  
      array_column($array, 'phone') 
     ); 

echo $array[$key]['first_name']; 
+0

我必須打印基於電話號碼的名字 –

+0

不工作。獲取同名 –

+0

電話和coutnry代碼合併 –