0

I have some SQL code that returns the a result {"agreetotos":"1","number":"0412345678","signupip":"123.456.789.10"}

I can access this data using PHP and output it as it appears above.

How can I, using PHP, access just the value for the key"number"
the result { } contains varying amounts of data, hence I need to search for the key "number" and return the value "0412345678" (etc)

2 Answers 2

1

The output is json, you can decode it and convert it to an array:

$json = '{"agreetotos":"1","number":"0412345678","signupip":"123.456.789.10"}';
$array = json_decode($json, true); //convert it to an array
//then

$number = $array['number']; //0412345678
Sign up to request clarification or add additional context in comments.

1 Comment

doh! json_decode, of course. I even said to myself at one point 'it looks like json' -- thanks :)
1

http://php.net/manual/en/function.json-decode.php json_deconde will convert this string to PHP table, and then you can simply do

echo $table['number'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.