Redeem value from a string in an array

Asked

Viewed 34 times

1

How do I get a string inside an array like the one below:

array(2) { 
    ["data"]=> array(1) { 
        ["charges"]=> array(1) { 
            [0]=> array(8) { 
                ["code"]=> int(433528162) 
                ["reference"]=> string(0) "" 
                ["dueDate"]=> string(10) "22/04/2019" 
                ["checkoutUrl"]=> string(100) "https://www.boletobancario.com/boletofacil/checkout/6E13300AFACDEE50594094562346gsfgwertE683D98BBE076EF" 
                ["link"]=> string(142) "https://www.boletobancario.com/boletofacil/charge/boleto.pdf?token=22904578:m:0bcf68c9aefc1f558218562a9efbad42bbefeabe82b248a437d66344950ba460" 
                ["installmentLink"]=> string(140) "https://www.boletobancario.com/boletofacil/charge/boleto.pdf?token=43188162:562c5278b4ac529291a711d461a721311b86da6ed1f0e02ba0e85848e0f37821" 
                ["payNumber"]=> string(54) "34190001275" 
                ["billetDetails"]=> array(4) { 
                    ["bankAccount"]=> string(12) "06" 
                    ["ourNumber"]=> string(14) "102-4" 
                    ["barcodeNumber"]=> string(44) "34196786700000012751094318816240655464808000" 
                    ["portfolio"]=> string(3) "109"
                }
            }
        }
    } ["success"]=> bool(true)
} 

The one I want to rescue is the ["checkoutUrl"] to make a redirect;

1 answer

1


Hello! to get the value you need to access the keys of the array. Assume that the $array variable is where the value of the array above is stored. In this case:

$checkoutUrl = $array["data"]["charges"][0]["checkoutUrl"];

See the example below:

        $array = [
        'data' => [
            'charges' => [
                0 => [
                    'code' => 433528162,
                    'reference' =>'',
                    'dueDate' => '22/04/2019',
                    'checkoutUrl' => 'https://www.boletobancario.com/boletofacil/checkout/6E13300AFACDEE50594094562346gsfgwertE683D98BBE076EF',
                    'link' => 'https://www.boletobancario.com/boletofacil/charge/boleto.pdf?token=22904578:m:0bcf68c9aefc1f558218562a9efbad42bbefeabe82b248a437d66344950ba460',
                    'installmentLink' => 'https://www.boletobancario.com/boletofacil/charge/boleto.pdf?token=43188162:562c5278b4ac529291a711d461a721311b86da6ed1f0e02ba0e85848e0f37821',
                    'payNumber' => '34190001275',
                    'billetDetails' => [
                        'bankAccount' => '06',
                        'ourNumber' => '102-4',
                        'barcodeNumber' => '34196786700000012751094318816240655464808000',
                        'portfolio' => '109',
                    ]
                ]
            ]
        ],
        'success' => true
    ];

    echo $array['data']['charges'][0]['checkoutUrl'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.