Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从对象php laravel获取数据_Php_Arrays_Laravel_Object - Fatal编程技术网

从对象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);