Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何访问此阵列_Php - Fatal编程技术网

Php 如何访问此阵列

Php 如何访问此阵列,php,Php,您好,我有一个数组结果,该结果由以下代码生成: //Get House Sales Date // Create a stream $username = "test"; $password = "test"; $remote_url2 = "https://www.streetcheck.co.uk/api/v1/postcode/".$cleanpostcode."/saleprices"; $opts2 = array( 'http'=>array( 'method'=>

您好,我有一个数组结果,该结果由以下代码生成:

//Get House Sales Date
// Create a stream
$username = "test";
$password = "test";
$remote_url2 = "https://www.streetcheck.co.uk/api/v1/postcode/".$cleanpostcode."/saleprices";
$opts2 = array(  'http'=>array(    'method'=>"GET", 'header' => "Authorization: Basic " . base64_encode("$username:$password")));
$context2 = stream_context_create($opts2);

//Open the file using the HTTP headers set above
$json2 = json_decode(file_get_contents($remote_url2, false, $context2));

//If Valid Results Returned
if($json2->message="ok")
{
    print_r($json2);
可以看到查询结果

我需要能够为每个结果插入值到另一个表中,到目前为止,我看到的是这样的情况:

foreach ($json2->result->sales as $item1)
{
    $pricepaid = $json2->result->sales->pricePaidGBP;
    $propertytype = $json2->result->sales->propertyType;
    $holding = $json2->result->sales->holding;
    $nameornumber = $json2->result->sales->nameOrNumber;
    $fulllocation = $json2->result->sales->fullLocation;
    $dateoftransfer = $json2->result->sales->dateOfTransfer;
但是结果返回为空,我做错了什么请>

转换为数组-

$json2 = json_decode(file_get_contents($remote_url2, false, $context2), true);
然后您可以像这样检索每个项目-

foreach ($json2 as $item)
  {
  $pricepaid = $item['result']['sales']['pricePaidGBP'];
  // ... the rest of the items
你试过这个吗:

foreach ($json2->result->sales as $item) {
    $pricepaid = $item->pricePaidGBP;
    $propertytype = $item->propertyType;
    $holding = $item->holding;
    $nameornumber = $item->nameOrNumber;
    $fulllocation = $item->fullLocation;
    $dateoftransfer = $item->dateOfTransfer;
    ...
}

它看起来像是编辑了objectPost中的一个数组,但在这里它仍然是一个数组数组,您必须为循环创建一个
。可能需要
$pricepade=$item1->pricePaidGBP
。否则,为什么还要麻烦循环“->result->sales”,然后完全忽略循环为您生成的变量呢?