从对象php laravel获取数据
嗨伙计们我需要一些帮助 我的变量从对象php laravel获取数据,php,arrays,laravel,object,Php,Arrays,Laravel,Object,嗨伙计们我需要一些帮助 我的变量$a具有[{“id”:“[1,2,3]”}]类型为对象,现在我需要第一个id,即在本例中,我需要1。如何从变量$a获取ut 当我将其转储时,打印如下 class Illuminate\Support\Collection#1230 (1) { protected $items => array(1) { [0] => class stdClass#1221 (1) { public $a => st
$a
具有[{“id”:“[1,2,3]”}]
类型为对象
,现在我需要第一个id
,即在本例中,我需要1
。如何从变量$a
获取ut
当我将其转储时,打印如下
class Illuminate\Support\Collection#1230 (1) {
protected $items =>
array(1) {
[0] =>
class stdClass#1221 (1) {
public $a =>
string(9) "[1, 2, 3]"
}
}
}
谢谢。什么是
$a
的类
它是illumb\Database\elount\Model
的扩展吗
也许是这样:
$firstId=当前($a->id);
编辑:
我在你的垃圾堆上没有看到id
current(json_decode($a->first()->id))
或
你能进入吗
echo $a->id; // outputs strings "[1,2,3]"
如果是,则使用json_decode对其进行解码
$array = json_decode($a->id);
$firstElement = current($array);
试试($a[0])->id[1]
我已经更新了这个问题,你能检查一下吗。你救了我一天!
$array = json_decode($a->id);
$firstElement = current($array);