Php Laravel 4中的阵列偏移错误
我有以下数组Php Laravel 4中的阵列偏移错误,php,arrays,laravel-4,Php,Arrays,Laravel 4,我有以下数组 object(Illuminate\Database\Eloquent\Collection)#96 (1) { ["items":protected]=> array(2) { [0]=> object(Answer)#97 (20) { ["connection":protected]=> NULL ["table":protected]=>
object(Illuminate\Database\Eloquent\Collection)#96 (1) {
["items":protected]=>
array(2) {
[0]=>
object(Answer)#97 (20) {
["connection":protected]=>
NULL
["table":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["perPage":protected]=>
int(15)
["incrementing"]=>
bool(true)
["timestamps"]=>
bool(true)
["attributes":protected]=>
array(6) {
["id"]=>
int(457256)
["question_id"]=>
int(3124)
["user_id"]=>
int(1235)
["answer_text"]=>
string(44) "Sincere Architects Engineers Private Limited"
["created_at"]=>
string(19) "2015-08-10 06:18:06"
["updated_at"]=>
string(19) "2015-08-10 06:39:33"
}
["original":protected]=>
array(6) {
["id"]=>
int(457256)
["question_id"]=>
int(3124)
["user_id"]=>
int(1235)
["answer_text"]=>
string(44) "Sincere Architects Engineers Private Limited"
["created_at"]=>
string(19) "2015-08-10 06:18:06"
["updated_at"]=>
string(19) "2015-08-10 06:39:33"
}
["relations":protected]=>
array(0) {
}
["hidden":protected]=>
array(0) {
}
["visible":protected]=>
array(0) {
}
["appends":protected]=>
array(0) {
}
["fillable":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["dates":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["with":protected]=>
array(0) {
}
["morphClass":protected]=>
NULL
["exists"]=>
bool(true)
}
[1]=>
object(Answer)#98 (20) {
["connection":protected]=>
NULL
["table":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["perPage":protected]=>
int(15)
["incrementing"]=>
bool(true)
["timestamps"]=>
bool(true)
["attributes":protected]=>
array(6) {
["id"]=>
int(457257)
["question_id"]=>
int(3125)
["user_id"]=>
int(1235)
["answer_text"]=>
string(14) "Anoop Bartaria"
["created_at"]=>
string(19) "2015-08-10 06:18:06"
["updated_at"]=>
string(19) "2015-08-10 06:39:33"
}
["original":protected]=>
array(6) {
["id"]=>
int(457257)
["question_id"]=>
int(3125)
["user_id"]=>
int(1235)
["answer_text"]=>
string(14) "Anoop Bartaria"
["created_at"]=>
string(19) "2015-08-10 06:18:06"
["updated_at"]=>
string(19) "2015-08-10 06:39:33"
}
["relations":protected]=>
array(0) {
}
["hidden":protected]=>
array(0) {
}
["visible":protected]=>
array(0) {
}
["appends":protected]=>
array(0) {
}
["fillable":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["dates":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["with":protected]=>
array(0) {
}
["morphClass":protected]=>
NULL
["exists"]=>
bool(true)
}
}
}
它清楚地表明它有两个值,分别是[0]和[1]
,但当我
var\u转储(数组[0])
它表示偏移错误:0
任何关于这一点的线索都将不胜感激
谢谢实际上您没有数组,您有一个Colleciton对象,您可以使用all()方法获取项目,然后可以转储返回的数组。请尝试以下操作
var_dump(json_decode($array,true)[0])代码>
json\u decode($array,true)
-->此语句将集合对象转换为数组。完成此操作后,可以使用数组索引访问数组
谢谢:)您可以使用dd($array->toArray())代码>以数组形式打印。它转换数组中的集合。同样,您可以使用dd($array->toJson())
以Json格式打印
希望有此帮助。illumb\Database\elount\Collection
扩展了illumb\Support\Collection
,它实现了arrayaaccess
。这意味着集合对象可以像数组一样使用;应该行得通