<?php
$arr = json_decode('{"@attributes":{"Status":"OK"},"Errors":{},"Warnings":{},"RequestedCommand":"namecheap.users.getpricing","CommandResponse":{"@attributes":{"Type":"namecheap.users.getPricing"},"UserGetPricingResult":{"ProductType":{"@attributes":{"Name":"domains"},"ProductCategory":[{"@attributes":{"Name":"reactivate"},"Product":{"@attributes":{"Name":"com"},"Price":{"@attributes":{"Duration":"1","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}}}},{"@attributes":{"Name":"register"},"Product":{"@attributes":{"Name":"com"},"Price":[{"@attributes":{"Duration":"1","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"2","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"3","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"4","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"5","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"6","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"7","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"8","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"9","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"10","DurationType":"YEAR","Price":"13.98","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.98","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.98","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}}]}},{"@attributes":{"Name":"renew"},"Product":{"@attributes":{"Name":"com"},"Price":[{"@attributes":{"Duration":"1","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"2","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"3","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"4","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"5","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"6","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"7","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"8","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}},{"@attributes":{"Duration":"9","DurationType":"YEAR","Price":"14.58","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"14.58","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"14.58","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}}]}},{"@attributes":{"Name":"transfer"},"Product":{"@attributes":{"Name":"com"},"Price":{"@attributes":{"Duration":"1","DurationType":"YEAR","Price":"13.78","PricingType":"MULTIPLE","AdditionalCost":"0.18","RegularPrice":"13.78","RegularPriceType":"MULTIPLE","RegularAdditionalCost":"0.18","RegularAdditionalCostType":"MULTIPLE","YourPrice":"13.78","YourPriceType":"MULTIPLE","YourAdditonalCost":"0.18","YourAdditonalCostType":"MULTIPLE","PromotionPrice":"0.0","Currency":"USD"}}}}]}}},"Server":"PHX01SBAPIEXT06","GMTTimeDifference":"--4:00","ExecutionTime":"0.065"}', true);

function getRegisterPrice($domainTLD, $newArr) {
    // Extract the "Register" product category for the target TLD
    $registerCategory = array_filter($newArr['CommandResponse']['UserGetPricingResult']['ProductType']['ProductCategory'], function ($category) use ($domainTLD) {
        //var_dump($category);
        $catName = $category['@attributes']['Name'];
        $prodName = $category['Product']['@attributes']['Name'];
        //echo "Cat: $catName\nProduct: $prodName\n";
        return $catName === 'register' && $prodName === $domainTLD;
    });
	//var_dump($registerCategory);
    // Extract the prices for the 1-year duration from the "register" category for the target TLD
    $registerPrices = array_column($registerCategory, 'Product');
    //var_dump($registerPrices);
    $registerPriceForOneYear = null;
    foreach ($registerPrices as $product) {
        foreach ($product['Price'] as $price) {
            if ($price['@attributes']['Duration'] == 1 && $price['@attributes']['DurationType'] == 'YEAR') {
                $registerPriceForOneYear = $price['@attributes']['Price'];
                break 2; // Exit both loops once the price for 1 year is found
            }
        }
    }
    return $registerPriceForOneYear;
}   

var_dump(getRegisterPrice('com', $arr));

