2017-08-01 48 views
0

我在PHP代码阵列获得价值:从性病对象(PHP)

$stuff = array($this->complaint_model->get_reply($id)->result()); 

    print_r($stuff); 

结果:

Array (
    [0] => Array (
     [0] => stdClass Object (
      [id_customer] => 21 
      [id_complaint] => 2 
      [id] => 4 
      [nama_customer] => Muhammad Bima Zehansyah 
      [from] => Admin 
      [balasan] => coba update 
     ) 
    ) 
) 

我的问题是,如何让值nama_customer]?人前THX

回答

0

得到这样

$stuff[0][0]->nama_customer 

这里有值多维数组对象这就是为什么你需要先斯格特×2阵列像$stuff[0][0]然后像$stuff[0][0]->nama_customer

+0

THX兄弟的份额! –

+0

欢迎您通过接受我的回答来关闭您的问题:) –

1

尝试对象此

$stuff = array($this->complaint_model->get_reply($id)->result()); 
echo $stuffVal = $stuff[0][0]->nama_customer; 
+0

$ stuffVal绝对没有必要 – Neodan

+0

发挥得好的兄弟! –

0

实际上,您不需要将结果放入其他array,并且检查结果是否为空是明智的做法。 所以你只需要第一个项目从你的结果(这是一个对象),并调用参数nama_customer

$stuff = $this->complaint_model->get_reply($id)->result(); 
if (!empty($stuff[0])) 
    echo $stuff[0]->nama_customer; 
+0

不错的答案兄弟!做得好 –