将数组对象推入php中的另一个数组对象

时间:2017-08-29 05:32:54

标签: php arrays object

我将一个对象推入另一个对象时出错。但是第二个对象是一个数组,在一个数组中有一个对象。我该如何解决这个原因我想将它添加到我的对象

我的对象就像这样

我想将 Object2 添加到 Object1

Objet1

stdClass Object
(
    [id_laporan_pemeriksa] => 5
    [no_pkpt] => SNE
    [tgl_pkpt] => 2010
    [no_penugasan] => ST-4000/PW25/2/2017
    [tgl_penugasan] => 2017-08-09
    [judul_laporan] => Masukkan Kode disini
    [no_laporan] => LBINA-9000/PW25/2/2017
    [tgl_laporan] => 2017-08-01
    [tahun_anggaran_penugasan] => 2009
    [nilai_anggaran_penugasan] => 10000000
    [realisasi_anggaran_penugasan] => 100000000
    [jenis_anggaran_penugasan] => Utang
    [sumber_laporan] => Inspektorat Maluku
    [nama_sumber_penugasan] => PKPT
    [nama_ketua_tim] => Abdul Rofiek, Ak.
    [nama_pengendali_teknis] => Alfian Massagony, S.E.
    [nama_unit_penugasan] => Irban Wil. I
    [nama_penugasan] => Penjaminan
    [nama_sub_penugasan] => Audit
    [id_s_sub_penugasan] => 010105
    [nama_s_sub_penugasan] => Audit atas hal-hal lain di bidang kepegawaian.
)

Object2的

stdClass Object
(
    [id] => 3
    [data_sebab] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 4
                    [data_rekomendasi] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [id] => 4

                                    [data_tindak_lanjut] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [id] => 9

                                                    [tgl_tindak_lanjut] => 0000-00-00
                                                )

                                        )

                                )

                            [1] => stdClass Object
                                (
                                    [id] => 5
                                    [id_rekomendasi] => 
                                    [data_tindak_lanjut] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [id] => 10
                                                    [id_tindak_lanjut] => 
                                                    [tgl_tindak_lanjut] => 0000-00-00
                                                )

                                            [1] => stdClass Object
                                                (
                                                    [id] => 11
                                                    [id_tindak_lanjut] => 
                                                    [tgl_tindak_lanjut] => 0000-00-00
                                                )

                                        )

                                )

                        )

                )

        )

)

我试过了

  $Object1['data']->$Object2;

但我收到了错误

  

无法使用stdClass类型的对象作为数组

3 个答案:

答案 0 :(得分:4)

应该是:

$Object1->data = $Object2; // it will create data element with obj2 as value

答案 1 :(得分:3)

#import "ARBot-Swift.h" @interface ChatScreenViewController : JSQMessagesViewController <SpeechRecognizerDelegate> 添加为$Object2的属性的语法是:

$Object1

或者:

$Object1->Object2 = $Object2;

答案 2 :(得分:1)

由于对象是对象而不是数组,因此使用:

$Object1['data']->$Object2;

不会工作。但是,执行以下操作将起作用:

$Object1->data = $Object2;