0

how to get the object name? e.g: “XXX.HOSTNAME”

$json = '{
    "XXX.HOSTNAME": {
        "IP": "123.195.214.93",
        "IP6": "",
        "DOCUMENT_ROOT": "/home/public_html/",
        "U_DISK": "154",
        "U_BANDWIDTH": "0",
        "TPL": "default",
        "ALIAS": "www.org",
        "STATS": "",
        "STATS_USER": "",
        "SSL": "yes",
        "SSL_HOME": "same",
        "LETSENCRYPT": "yes",
        "FTP_USER": "",
        "FTP_PATH": "",
        "AUTH_USER": "",
        "BACKEND": "default",
        "PROXY": "default",
        "PROXY_EXT": "jpeg,m4v,mkv,mov,mpeg,mpg,wmv,exe",
        "SUSPENDED": "no",
        "TIME": "15:56:54",
        "DATE": "2023-03-04"
    }
}';

php beginner,I can get the subordinate properties, but I don't know how to get the name of the object ... ...

3
  • array_key_first(json_decode($json, true)); 3v4l.org/sf3CP Commented Sep 23, 2023 at 23:44
  • print_r(array_keys(json_decode($json, true))); Commented Sep 24, 2023 at 0:27
  • If there is more than one key, that will give you all of them in an array that you can loop over. For your sample data, with only one key, the code I suggested will give you the key with no further processing. Commented Sep 24, 2023 at 0:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.