php - Warning: Illegal string offset 'id' -


i have following code:

 $charge = \stripe\charge::create(array(       'customer' => $customer->id,       'amount'   => $amount,       'currency' => 'cad',             'capture' => 'false',        'description'=>  $coursetitle    ));   $charge_json = $charge->__tojson();  echo $charge_json['id'];  echo "<pre>";  var_dump($charge_json);   echo "</pre>";   } 

where intent grab whats on green below: enter image description here

but receive following error:

warning: illegal string offset 'id'  

i later use variable in mysql query

it json string far can tell.

you need convert array or object using json_decode:

$array = json_decode($charge_json, true); $object = json_decode($charge_json); 

for array, access are.

for object, access like: $object->id

if stripe provides way retrieve object or array already, should use that.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -