2

我正在尝试弄清楚如何仅显示第一个返回值(电话号码)。目前,此代码返回所有可用号码,但我只想向客户显示一个。

这是代码。我希望有人能帮帮忙。你看,我对此很陌生,我尝试了一些,但它们没有奏效。

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC1f3ccf29618exxxxx"; 
$token = "{{Auth_Token}}"; 
$client = new Services_Twilio($sid, $token);

$numbers = $client->account->available_phone_numbers->getList('GB', 'Local', array(
        "Contains" => "44161"
    ));

foreach($numbers->available_phone_numbers as $number) { 
echo $number->phone_number;
}

?>

目前我得到一个列表如下:

+441618503707+441618503748+441618502214+441618502601+441618502327+441618503631+441618503785+441618503437+441618503432+441618503758+441618503593+441618503404+441618503794+441618502289+441618503684+441618503519+441618503629+441618503810+441618503704+441618503742+441618503557+441618503302+441618503604+441618503539+441618503044+441618503298+441618503799+441618503753+441618503447+441618503801

我只想显示第一个值 IE+441618503707

感谢您的帮助,我可能不会立即回复,因为这是目前正在进行的众多项目之一。请放心,尽管我的其他项目都在 Infusionsoft 上,但我不会经常涉足 API/PHP!

4

1 回答 1

1

那么你可以使用这个

echo $numbers->available_phone_numbers[0]->phone_number;

它将包含数组中的第一个。

更新

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC1f3ccf29618exxxxx"; 
$token = "{{Auth_Token}}"; 
$client = new Services_Twilio($sid, $token);

$numbers = $client->account->available_phone_numbers->getList('GB', 'Local', array(
        "Contains" => "44161"
    ));

echo $numbers->available_phone_numbers[0]->phone_number;

?>
于 2015-08-24T05:41:16.413 回答