Array of PHP Objects

后端 未结 5 1373
孤城傲影
孤城傲影 2020-12-02 06:29

So I have been searching for a while and cannot find the answer to a simple question. Is it possible to have an array of objects in PHP? Such as:

$ar=array()         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 07:10

    Arrays can hold pointers so when I want an array of objects I do that.

    $a = array();
    $o = new Whatever_Class();
    $a[] = &$o;
    print_r($a);
    

    This will show that the object is referenced and accessible through the array.

提交回复
热议问题