doulangxun7769 2018-06-03 17:50
浏览 88

如何删除受保护阵列中的数组?

My data returns look like:

Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [admin] => Admin
            [user] => User
            [abcd] => Abcd
        )

)

I want to remove admin array in above result. I tried this way unset($data->items->admin) Getting the error message Property [items] does not exist on this collection instance..

  • 写回答

1条回答 默认 最新

  • doushang1890 2018-06-03 17:58
    关注

    Protected is a visibility permission set. http://php.net/manual/en/language.oop5.visibility.php

    from the looks of the error it looks like your forgetting to extend the sub class.

    Here is an example of what your trying to do.

    class a{
        protected $b;
        function __construct(){
            $this->b = Array('test'=>Array());
        }
    }
    
    class b extends a{
        function __construct(){
            parent::__construct();// construct extended class
            out($this->b); //returns Array ( [test] => Array ( ) ) 
            unset($this->b['test']);
            out($this->b); // returns Array ( )
        }
    }
    
    function out($arr){ // function to output text
        echo "<pre>";
        print_r($arr);
        echo "</pre>";
    }
    
    $b_test = new b();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决