airborne305 Posted January 3, 2014 Share Posted January 3, 2014 Sorry if my wording/terminalogy on the discription is wrong. I'm new to PHP, so i'll do my best to detail what im trying to do. The PHP is doing what i need it to do. But i do not need to print the whole response. I only need the [address] and [pubkey] values as variables. I have read a few tutorials, but they assume i already know the strings to be converted to variables. Please help Code... <?php require_once 'jsonClient.php'; $service = new jsonClient('http://ooples:[email protected]:18332/'); $apple = array ($service->validateaddress("1234567890")); print_r ($apple); ?> Response... Array ( [0] => Array ( [isvalid] => 1 [address] => 1234567890 [ismine] => 1 [isscript] => [pubkey] => hqwiuehf9 [iscompressed] => 1 [account] => foo ) ) Link to comment https://forums.phpfreaks.com/topic/285048-array-parsing-to-variable-from-echoprint-response/ Share on other sites More sharing options...
denno020 Posted January 3, 2014 Share Posted January 3, 2014 Tp print 'address' and 'pubkey', you will access it like this: $apple[0]['address'] $apple[0]['pubkey'] Your variable $apple is an array, with 1 element, which is another array. That array then has all of your values, so that's why you need the '[0]' before the index of the value you want (as array's are 0-indexed, meaning the first value is always at position 0, second value at position 1, and so on). Hopefully that helps you out. Denno Edit: I just read through all of your code (instead of just looking at the print_r result), to avoid the need of the [0], then change: $apple = array ($service->validateaddress("1234567890")); //to $apple = $service->validateaddress("1234567890"); Then you access the values like this: echo $apple['address']; echo $apple['pubkey']; Link to comment https://forums.phpfreaks.com/topic/285048-array-parsing-to-variable-from-echoprint-response/#findComment-1463655 Share on other sites More sharing options...
airborne305 Posted January 10, 2014 Author Share Posted January 10, 2014 Hi, thanks for your response. great help for a newbe. :-) Link to comment https://forums.phpfreaks.com/topic/285048-array-parsing-to-variable-from-echoprint-response/#findComment-1464654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.