显示返回列表中的单个结果

时间:2015-08-24 05:33:24

标签: php api twilio twilio-php

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

这是代码。我希望有人能帮帮忙。我是新手,你看,我已经尝试了一些,但他们没有工作。

<?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!

1 个答案:

答案 0 :(得分: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;

?>