PHPerたるもの最短で値にアクセスしなければならない。水の呼吸。
思考を使わなくて良いところで頑張っちゃうと進捗が死ぬ。
もくじ
ケース① オブジェクト
["original":protected]=>
array(39) {
["animal_id"]=>
int(777)
}
}
["relations":protected]=>
array(1) {
["AnimalTargets"]=>
object(Illuminate\Database\Eloquent\Collection)#1912 (1) {
["items":protected]=>
array(1) {
[0]=>
object(App\Models\AnimalTarget)#3616 (26) {
["fillable":protected]=>
array(4) {
[0]=>
string(9) "animal_id"
[1]=>
string(8) "zoo_id"
}
["connection":protected]=>
string(6) "AlibabaDB"
["table":protected]=>
NULL
["attributes":protected]=>
array(7) {
["animal_id"]=>
string(10) "711"
["is_kawaii"]=>
int(1) ←●この値を取得したいぞ!
アクセス方法
$instance->relations['AnimalTargets'][0]->attributes['is_kawaii'];
考え方
- array配下のものはkey
- オブジェクトは[‘name’:protected]などアクセス修飾子がついている
ケース②
dd($attr)
..array:1 [
0 => {#2063
+"is_kawaii": 1 ←●この値を取得したい
}
]
アクセス方法
echo $attr[0]->is_kawaii; // 1
考え方
- array直下のものはkey
- {key: value}についてはプロパティでアクセスする




