PHP API返回一个数组 - 需要在变量中重用它

PHP API返回一个数组 - 需要在变量中重用它

问题描述:

I have a PHP script that dumps data from an API.

The dump is an array

 print_r($answer); 

outputs

 Array ( [success] => 1 [serial] => s001 [url] => http://gooole.com )

I want to have another variable called $url that holds the value url from the array (held in $answer) in PHP.

I'm unfamiliar with this.

check out extract() it will take the keys from an array, and create variable of the same name to store them in. There are a few flags you can pass it, to determine exactly what it does with things like pre-existing variables of the same name.

EDIT: as mentioned in the comments on your question, though, $url = $answer['url']; is probably the simplest way to go.