簡體   English   中英

如何在 PHP 中打印對象數組的一個元素?

[英]How to print one element of an array of an object in 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
            }
        }
}

我怎樣才能只獲得“nomeempresa”值?

當我嘗試$veraplicacao["nomeempresa"] ,出現以下錯誤:

未定義索引: nomeempresa

當我嘗試$veraplicacao->nomeempresa ,出現以下錯誤:

此集合實例上不存在屬性 [nomeempresa]。

當我嘗試$veraplicacao->nomeempresa ,出現以下錯誤:

不能使用 stdClass 類型的對象作為數組

要獲得您可以使用first()之后的屬性:

$veraplicacao->first()->nomeempresa;

有關集合的更多信息,我建議查看文檔


或者,由於 Collection 實現了ArrayAccess,您可以只使用數組中值的索引:

$veraplicacao[0]->nomeempresa;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM