如果电话号码与字符串匹配,我需要打印一个数组,并根据该数字显示第一个名字?我必须用名字打印相应的号码。如何实现
$phone_number = 8056006655;
Array ( [0] => Array ( [phone] => 8056006655 [country_code] => +91 [status] => [email] => +918056006655@sugaldamanifoundations.com [call_groups] => Array ( ) [role] => [wrap_up_times] => Array ( ) [first_name] => Dominic [id] => 850688 [opt_in] => 1 [last_name] => )
答案 0 :(得分:0)
你正在寻找它在php之前的array_search中的array_column。 5.5你需要一个丑陋的foreach,但从5.5你可以使用类似下面的东西。
$phone_number = 8056006655;
$array = array(
[0] => Array (
[phone] => 8056006655
[country_code] => +91
[status] =>
[email] => +918056006655@sugaldamanifoundations.com
[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'];