0

I have set up a curl to return some values however i'm unsure how to retrieve child values. When i try to retrieve $bankname it's empty because its a child value i believe.

$bin = "492182";
$url = "https://lookup.binlist.net/" . $bin;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
$details = json_decode($resp, true);
$cardscheme = strtoupper($details['scheme']);
$cardtype = ucwords($details['type']);
$cardbrand = ucwords($details['brand']);
$bankname = strtoupper($details['bank']); //<<< need this value

Below is the api:

    curl / https
    curl -H "Accept-Version: 3" "https://lookup.binlist.net/45717360"
    {
      "number": {
        "length": 16,
        "luhn": true
      },
      "scheme": "visa",
      "type": "debit",
      "brand": "Visa/Dankort",
      "prepaid": false,
      "country": {
        "numeric": "208",
        "alpha2": "DK",
        "name": "Denmark",
        "emoji": "🇩🇰",
        "currency": "DKK",
        "latitude": 56,
        "longitude": 10
      },
      "bank": {
        "name": "Jyske Bank",
        "url": "www.jyskebank.dk",
        "phone": "+4589893300",
        "city": "Hjørring"
      }
    }

Any help appreciated!

2
  • 1
    try $details['bank']['name'] Commented Dec 27, 2018 at 13:55
  • 1
    worked like a charm! thanks Commented Dec 28, 2018 at 10:35

1 Answer 1

1

As @Sfili comment, if you want the bank name use this example:

$s = '{"type":"debit", "brand": "Visa_Dankort", "bank": {"name": "Jyske Bank", "url": "www.jyskebank.dk"}}';
$details = json_decode($s, true);
echo $details["bank"]["name"];

This will output: Jyske Bank.

You are unable to get this line $bankname = strtoupper($details['bank']); because $details['bank'] is an array and strtoupper expecting string.

If I understand your meaning just do: $bankname = strtoupper($details['bank']['name']);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.