Using the API, I get a response from the $result variable of the following form:

 echo $result; {"result":"success","order_id":100888,"order_number":10} 

How correctly from the line above pull out this part of the "order_id":100888 and add it to the variable. At first glance, this can be done using foreach.

The result should be: delivery_order_id = '100888'

    1 answer 1

    Get familiar with the json_decode () function .

     $json = '{"result":"success","order_id":100888,"order_number":10}'; $delivery_order_id = json_decode($json)->order_id; var_dump( $delivery_order_id ); 
    • I understand this line is optional here var_dump( $delivery_order_id ); , only to visually show the result? - Alexandra Kuznetsova
    • @ Aleksandra Kuznetsova is absolutely right. - Edward
    • @KAGG Design does not seem to have such a variable wp_json_decode (), only wp_json_encode (). - Alexandra Kuznetsova