如何在PHP

时间:2017-09-11 14:07:01

标签: php

我有像

这样的php数组
Array 
( 
[0] => stdClass Object 
    ( [type] => MILESTONE
      [creator] => xyz 
      [tpid] => abc 
      [docname] => STS 
      [items] => stdClass Object 
        ( 
            [MILESTONE_CODE] => ARPOD 
            [MILESTONE_TYPE] => ACT 
            [MILESTONE_DESCRIPTION] => Arrival at Port of Discharge 
            [TRIGGER_EVENT] => Y [ENVIRONMENT] => T 
        ) 
    ) 
[1] => stdClass Object 
    ( 
        [type] => MILESTONE 
        [creator] => xyz 
        [tpid] => abc 
        [docname] => STS 
        [items] => stdClass Object 
        ( 
            [MILESTONE_CODE] => BKD 
            [MILESTONE_TYPE] => EST 
            [MILESTONE_DESCRIPTION] => Booking created 
            [TRIGGER_EVENT] => N 
            [ENVIRONMENT] => P 
        ) 
    ) 
)

有2个php文件写

文件1:在这个文件中,我正在解码我的json数据并得到了数组

$data = json_decode(file_get_contents("php://input"));

 // print_r($data);exit;

foreach ($data as $value){

$TP->createTPConfig($data);  // Here I am calling method for each index of array
} 

文件2:在这个文件中,我编写了将数据插入oracle数据库的方法。

function createTPConfig($dataToBeInsert){

// print_r($dataToBeInsert);exit; // till here I am getting above array

// written insert query here 

}

现在在文件2中,我想访问

的数组值

[type][creator][tpid][docname]

再次

我想foreach(repeat)

循环[items]

并希望访问

的键和值

[MILESTONE_CODE][MILESTONE_TYPE][MILESTONE_DESCRIPTION][TRIGGER_EVENT]

并将键和值都插入数据库

任何人都可以提供帮助......我们将非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

只需更改

$data = json_decode(file_get_contents("php://input"));

$data = json_decode(file_get_contents("php://input"), true);

这将为您提供一个完整的阵列。义务人员链接:json decode