> For the complete documentation index, see [llms.txt](https://tobyisme.gitbook.io/integrated/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tobyisme.gitbook.io/integrated/php-jsonge-shi-de-zhuan-huan.md).

# PHP-json格式的轉換

在做一個專案下碰到兩個json格式，

1. 一個是物件：呼叫的方式是$data->key
2. 另一個是陣列：呼叫的方式是$data\['key']

一個專案最好只要有一種格式就好，如果出現兩種，就必須把一個轉成另一個，我是習慣轉成陣列格式。

```
$data = (array)$data; //這樣就可以強制轉成陣列



// convert json to array
$array = json_decode($json, true);
//  create a new collection instance from the array
collect($array);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tobyisme.gitbook.io/integrated/php-jsonge-shi-de-zhuan-huan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
