Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示返回列表中的单个结果_Php_Api_Twilio_Twilio Php - Fatal编程技术网

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

Php 显示返回列表中的单个结果,php,api,twilio,twilio-php,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 Tok

我正在努力解决如何只显示第一个返回值(电话号码)。目前,该代码返回所有可用的数字,但我只想向客户显示一个

这是密码。我希望有人能帮忙。我是个新手,你看,我试过一些,但都没用

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

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

那么你可以使用这个

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;

?>


Hi@showstepper,我试过了,它确实多次返回一个电话号码。有没有办法让它只显示一次?不要在foreach dude中使用它。在foreach外面使用它。嗨@showstepper,谢谢你在这方面的帮助,效果非常好!第二步,购买号码,帮助我花钱的穷人哈哈!
<?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;

?>