? ???? ?????? ???? ?? ???? ?? ?????, ???? ??? ?????, ?? ?? ??? ???? ? ? ????. ??? PHP ?????? thinkphp5? ?? ?????? ???? ??? ??????. ??? ??? ?? ?? ????? ???? ??? ???? ?? ??? ???? ???. ? ????? ? ??? ?? ???? ??? ??? ?????.
1. toArray ???? ?????
thinkphp5??? ?? ?? ???? ??? ?????, toArray ???? ??? ? ????. ? ???? ?? ???? ????? ???? ???. ?:
$user?=?UserModel::get(1);//獲取ID為1的用戶對(duì)象 $userArray?=?$user->toArray();//將$user轉(zhuǎn)為數(shù)組
? ??? ?? ???? ??? ??? ??? ??? ????. ??? ? ???? ? ?? ??? ????. ?? ?? ??? ?? ??? ??? ?? toArray ???? ???? ??? ???? ??? ??? ???? ????? ??? ???? ????. ??? ?? ?? ??? ??? ??? ??(?, ???? ??? ????? ?? ??) ????? ??? ???? ????.
2. toArray ??? ???
??? ??? ?? ??? ???? ?? toArray ???? ??? ???? ??? ??? ? ????. ???? ??? ???? toArray ???? ????? ???? ???? ??? ???? ????. ?:
class?UserModel?extends?Model { ????protected?$table?=?'user'; ????public?function?groups() ????{ ????????return?$this->belongsTo('GroupModel',?'group_id',?'id'); ????} ????public?function?toArray() ????{ ????????$data?=?parent::toArray();//調(diào)用父類toArray方法,獲取原始數(shù)組 ????????//獲取關(guān)聯(lián)關(guān)系的數(shù)據(jù) ????????$groupsData?=?$this->getRelation('groups')->toArray(); ????????//獲取虛擬字段的數(shù)據(jù) ????????$data['full_name']?=?$this->first_name?.?'?'?.?$this->last_name; ????????//將關(guān)聯(lián)關(guān)系和虛擬字段的數(shù)據(jù)合并到原始數(shù)組中 ????????$data?=?array_merge($data,?$groupsData); ????????return?$data; ????} }
? ???? ?? ??? ?? ??? ???? UserModel ??? ?????. ? ? ???? ??? ???? ?? toArray ???? ??????. ? ?????? ?? parent::toArray() ???? ???? ?? ??? ????. ????, ??? ???? ?? ??? ???? ???? ???? ?? ??? ??????. ????? ??? ??? ?????.
3. ?? ?? ??
thinkphp5??? ?? ??? ???? ??? ??? ??? ??? ?? ????. ??? ???? ??? ???? ??? ???? ? ???? thinkphp5? ??? ?????. ?:
$userList?=?UserModel::all();//獲取用戶列表 $userArray?=?collection($userList)->toArray();//將$userList轉(zhuǎn)為數(shù)組
? ??? ??? ?? ? ?? ??? ??? ? ??? ????? ?? ?????. ??? ? ???? ??? ????. ?, ??? ????? ???? ?? ??? ????? ??? ? ??? ????. ? ??? ?? ?? ??? ??? ????? ???? ???? ????.
4. json ???? ?????
??? ??? ?? ??? json? ???? ???? ??? ??? ?? ????. ???? ??? json ???? ???? ???? json ???? ??? ?? json_decode ???? ???? json ???? ??? ???? ????. ?:
$user?=?UserModel::get(1);//獲取ID為1的用戶 $userJson?=?$user->toJson();//將$user轉(zhuǎn)為json字符串 $userArray?=?json_decode($userJson,?true);//將$userJson解碼為數(shù)組
? ??? ??? ???? ???? ??? ??? ?? ? ?? ??? ??? ? ??? ????. ??? ? ???? ???? ???? ? ? ?? ??? ????? ????. ??? ? ??? ?? ??? ???? ??? ???? ?? ???? ?? ?????.
5. ??
????? thinkphp5?? ???? ??? ???? ??? ?? ??? ??? ? ???? ??? ??? ????. ?? ????? ?? ?? ??? ??? ??? ? ????. ??? ???? ??? ???? ?? ?? ??? ???? ??? ? ????. ??? ?? ? ?? ??? ???? ?? ?? ?? ?? ??? ???? ?? ?? toArray ???? ???? ???? ? ????. , toArray ???? ??? ? ????. ?? ??? ???? ??? ????? json ???? ??? ? ????. ?? ??? ???? ??? ??? ???? ?? ?????.
? ??? thinkphp5?? ???? ??? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)