<p>To get the address you would do:    </p>

<pre><code>$result = json_decode($response, true);
$address = $result["result"]["address"];
</code></pre>

CC BY-SA 3.0
2017-08-19T17:06:59.303Z
Thanks.  The [0] was throwing a "undefined offset" error - so I removed it and it returns the address field now with   =>  $address = $result["result"]["address"];  <=  the var dump shows a  => string(34) <= in front of the address but I can hack the rest of the script fixed now.  I would not have figured that one out without your assistance.  Thanks - and all that come behind me to find this page thank you too.
wilburunion
CC BY-SA 3.0
2017-08-19T04:21:30.340Z
2017-08-20T15:29:27.000Z
2017-08-20T15:29:27.000Z
m1xolyd1an
<p>As you have convert response to array using json_decode so you can access by array element inside result.
You can access by echo $result["result"]["address"];</p>

CC BY-SA 4.0
2018-06-30T14:25:09.350Z
2018-06-30T14:25:09.350Z
Rushabh Madhu
<p>I use json_decode to vardump a return which yields</p>

<p>array(3) { ["jsonrpc"]=> string(3) "2.0" ["result"]=> array(13) { ["status"]=> string(7) "Pending" ["amount (BTC)"]=> string(10) "0.05130899" ["index_url"]=> . . . . [more fields  here] . . .  ["address"]=> string(34) "1GHHojoC4Ai1SPMN3YoNzemLNaaj2XFHKc" </p>

<p>I am trying to fill a variable with the text from the "address" field and I tried </p>

<p>$result =  json_decode($response, true);
   $address = $result->address;</p>

<p>but a varbump of $addrwss is NULL</p>

<p>any other variant like $result->"address" or $result->["address"] is improper syntax</p>

<p>Can someone tell me how to get at the text of the address field of a JSON PRC 2.0 response to put it in a variable in PHP</p>

CC BY-SA 3.0
2018-03-19T12:31:11.523Z
Welcome to Bitcoin.SE! You can help the site by marking answers as accepted if they are correct and address the question so that the question does not remain as "unanswered".
Willtech
<json-rpc><electrum><php>
trying to get text of a field in json rpc 2.0 response into ar PHP variable
wilburunion
# trying to get text of a field in json rpc 2.0 response into ar PHP variable

(Asked by: username_0 on 2017-08-19)

I use json\_decode to vardump a return which yields

array(3) { ["jsonrpc"]=> string(3) "2.0" ["result"]=> array(13) { ["status"]=> string(7) "Pending" ["amount (BTC)"]=> string(10) "0.05130899" ["index\_url"]=> . . . . [more fields here] . . . ["address"]=> string(34) "1GHHojoC4Ai1SPMN3YoNzemLNaaj2XFHKc"

I am trying to fill a variable with the text from the "address" field and I tried

$result = json\_decode($response, true);
$address = $result->address;

but a varbump of $addrwss is NULL

any other variant like $result->"address" or $result->["address"] is improper syntax

Can someone tell me how to get at the text of the address field of a JSON PRC 2.0 response to put it in a variable in PHP

**Tags:** json-rpc, electrum, php

> **Comments:**
> **username_1**: Welcome to Bitcoin.SE! You can help the site by marking answers as accepted if they are correct and address the question so that the question does not remain as "unanswered".  

---

## 2 answers

### Answer by username_2 on 2017-08-19. Score: 1

To get the address you would do:    
$result = json_decode($response, true);
$address = $result["result"]["address"];

> **Comments:**
> **username_0**: Thanks.  The [0] was throwing a "undefined offset" error - so I removed it and it returns the address field now with   =>  $address = $result["result"]["address"];  <=  the var dump shows a  => string(34) <= in front of the address but I can hack the rest of the script fixed now.  I would not have figured that one out without your assistance.  Thanks - and all that come behind me to find this page thank you too.  

---

### Answer by username_3 on 2018-06-30. Score: 1

As you have convert response to array using json\_decode so you can access by array element inside result.
You can access by echo $result["result"]["address"];


---

