2

I'm trying to work out how I can display the first returned value (phone number) only. At the moment this code returns ALL available numbers but I only want to display one to the customer.

Here's the code. I hope someone can help. I'm pretty new to this you see, I've tried a few bits but they haven't worked.

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

?>

Currently I get a list as follows:

+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

I would just like to display the first value IE +441618503707

Help appreciated, I may not respond right away as this is one of many projects on at the moment. Rest assured though my other projects are on Infusionsoft, I don't dabble in API/PHP too often!

user3666207
  • 29
  • 1
  • 8

1 Answers1

1

then you can use this

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

it will contains first in the array .

Update

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

?>
Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68
  • Hi @ShowStopper, I tried that and it does return one phone number just multiple times. Any ideas on how to get that displaying only the once? – user3666207 Aug 24 '15 at 05:48
  • don't use it in foreach dude. use it outside foreach. – Manoj Dhiman Aug 24 '15 at 05:59
  • Hi @ShowStopper, thanks for your help on this, that works perfectly! Onto step two, purchasing the number, gawd help the poor guy who's money I'm spending haha! – user3666207 Aug 24 '15 at 06:07