Carrier validation using Twilio

I try to validate a phone number and test carrier value.
How to set a loop using PHP and response in the case of false carrier?

<?php
 // Get the PHP helper library from twilio.com/docs/php/install 
 require "vendor/autoload.php"; 
 
 // Your Account Sid and Auth Token from twilio.com/user/account 
 $sid = "{{account_sid}}"; $token = "{{auth_token}}"; $client = new Lookups_Services_Twilio($sid, $token); 
 
 // Perform a carrier Lookup using a US country code 
 $number = $client->phone_numbers->get("+1XXX", array("CountryCode" => "US", "Type" => "carrier")); 
 
 // Log the carrier type and name 
 echo $number->carrier->type . "\r\n"; 
 
 // => mobile 
 echo $number->carrier->name;  // => Verizon ```
?>

what sort of loop rather depends on your input.

How to store into variable. Just an an example of phone number: +1 866 XXX XXX

carrier->type
carrier->name

Twilio Lookup allows you to get information about phone numbers programmatically. This information can include the name of the phone number’s carrier, their type (landline, mobile, VoIP, etc.), the name of the caller

How to store… what into a variable? The input? the output?

This will return a JSON response:

{
    "caller_name": null,
    "country_code": "US",
    "phone_number": "+18557477626",
    "national_format": "(855) 747-7626",
    "carrier": {
        "mobile_country_code": null,
        "mobile_network_code": null,
        "name": "Twilio - Toll-Free - SMS-Sybase365/MMS-SVR",
        "type": "voip",
        "error_code": null
    },

A phonebook REST API that you can use to check whether a number exists, format international numbers to local standards, determine whether a phone can receive text messages, and even discover information about the carrier associated with that phone number.
So, I like to information about the carrier associated with that phone number.

Which you’ve already got in your code…

So, we simply store variable:$carrier_name = carrier->name;

That should be $carrier_name = $number->carrier->name as there is no $carrier variable defined anywhere in your example.