从http请求获取php文件中的数组

从http请求获取php文件中的数组,php,file-get-contents,Php,File Get Contents,我正在学习php,我正在尝试使用Guzzle从http请求中获取一个php文件,然后从这些内容中获取一个特定数组,忽略其余内容。但我不确定如何获得该阵列 <?php require_once "vendor/autoload.php"; use GuzzleHttp\Client; $client = new Client(); $response = $client->request('GET', 'http://api-address/file.php'

我正在学习php,我正在尝试使用Guzzle从http请求中获取一个php文件,然后从这些内容中获取一个特定数组,忽略其余内容。但我不确定如何获得该阵列

<?php 
require_once "vendor/autoload.php";

use GuzzleHttp\Client;

$client = new Client();
$response = $client->request('GET', 'http://api-address/file.php');

$body = $response->getBody();
$decoded = json_decode($body, true);

$contents = file_get_contents($decoded);
您正在使用

json_decode($body, true);
该方法将内容转换为数组,这意味着如果您执行

var_dump($decoded);
您可以看到一个数组,其中包含数组

嗯,我是说,你可以

$array = [
 [
 'name' => 'stuff I need'
 ]
];
导航到$json_decode()数组

如果你问的是如何,那么,就使用下一步

$contentArray = $decoded[1] //With this you can get the array that you need.
您正在使用

json_decode($body, true);
该方法将内容转换为数组,这意味着如果您执行

var_dump($decoded);
您可以看到一个数组,其中包含数组

嗯,我是说,你可以

$array = [
 [
 'name' => 'stuff I need'
 ]
];
导航到$json_decode()数组

如果你问的是如何,那么,就使用下一步

$contentArray = $decoded[1] //With this you can get the array that you need.