Welcome Guest, Not a member yet? Register   Sign In
changing a collection into an array
#1

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.
proof that an old dog can learn new tricks
Reply
#2

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

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.
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB