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:booples@127.0.0.1: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 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/285048-array-parsing-to-variable-from-echoprint-response/ Share on other sites More sharing options...
Solution denno020 Posted January 3, 2014 Solution Share Posted January 3, 2014 (edited) 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']; Edited January 3, 2014 by denno020 Quote 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. :-) Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.