如何存取名稱中帶有空格的類別屬性?

Linda Hamilton
發布: 2024-10-18 15:42:03
原創
857 人瀏覽過

How to Access Class Properties with Spaces in Their Names?

Accessing Properties with Spaces in Class Objects

This question explores how to access class properties that contain spaces in their names. Consider the following example, wherein a stdClass object has properties named "[Sector]" and "[Date Found]":

<p>stdClass Object ([Sector] =&gt; Manufacturing [Date Found] =&gt; 2010-05-03 08:15:19)</p>
登入後複製

While accessing "[Sector]" using $object->Sector is straightforward, retrieving "[Date Found]" requires a different approach.

To access properties with spaces, enclose the property name within curly braces ({}). For instance, the following code snippet retrieves the value of "[Date Found]":

$object-&gt;{'Date Found'}
登入後複製

By utilizing this method, developers can efficiently access properties with spaces, ensuring flexibility and convenience in handling complex object structures.

以上是如何存取名稱中帶有空格的類別屬性?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!