CodeIgniter Forums
changing a collection into an array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: changing a collection into an array (/showthread.php?tid=83577)



changing a collection into an array - richb201 - 10-06-2022

I am running the code below. I thought that json_output would hold an array of the data, but instead it gets NULL. Why? 
 $stripe = new \Stripe\StripeClient($_SESSION['STRIPE_SECRET_KEY']);
        $js = $stripe->customers->all(['email' => $_SESSION['userid']]);
        $json_output=json_decode($js,true);

        $cust_id = $json_output->lastResponse->json->data[0]->id;
        $_SESSION['stripe_customer_number'] = $cust_id;
$cust_id also gets NULL.


RE: changing a collection into an array - superior - 10-07-2022

depends, what does $json_output holds, but the second argument on json_decode would be an array output.


RE: changing a collection into an array - richb201 - 10-07-2022

Now i have
$stripe = new \Stripe\StripeClient($_SESSION['STRIPE_SECRET_KEY']);
$customersResponse = $stripe->customers->all(['email' => $_SESSION['userid']]);
$customersArray= $customersResponse->data;
$_SESSION['stripe_customer_number'] = (string) $customersArray[0]->_values->id;

$customersArray yields an array of 10 objects (why 10?). But I need to get the _values.id in the first array element. I get a warning of use of undefined constant "_values". How can I "strip" the id out of object[0]? I am getting a warning that "_values" is an undefined constant.

$_SESSION['stripe_customer_number'] = (string) $customersArray[0]->_values->id; contains the string I need.