如何在PHP中打印对象数组的一个元素?

当我在我的变量$veraplicacao上使用var_dump时,我得到的结果如下:


object(Illuminate\Support\Collection)#351 (1) {

    ["items":protected]=>

        array(1) {

            [0]=> object(stdClass)#357 (11) {

                ["id"]=> int(1008)

                ["created_at"]=> NULL

                ["updated_at"]=> NULL

                ["nomeempresa"]=> string(11) "Teste teste"

                ["vagaaplicada"]=> string(6) "Testes"

                ["statusaplicacao"]=> int(4)

                ["pais"]=> string(6) "Brasil"

                ["estado"]=> string(16) "Distrito Federal"

                ["cidade"]=> string(12) "Plano Piloto"

                ["textocompleto"]=> string(16) "Teste 123"

                ["deleted_at"]=> NULL

            }

        }

}

我怎么能只得到“诺米姆普雷萨”值?


当我尝试时,我得到以下错误:$veraplicacao["nomeempresa"]


Undefined index: nomeempresa


当我尝试时,我得到以下错误:$veraplicacao->nomeempresa


属性 [无名名]在此集合实例上不存在。


当我尝试时,我得到以下错误:$veraplicacao->nomeempresa


不能使用 stdClass 类型的对象作为数组


梦里花落0921
浏览 154回答 1
1回答

大话西游666

要获取您所需的属性,可以先使用():$veraplicacao->first()->nomeempresa;有关集合的更多信息,我建议查看文档。或者,由于集合实现了数组访问,因此您只需使用数组中值的索引:$veraplicacao[0]->nomeempresa;
打开App,查看更多内容
随时随地看视频慕课网APP