Array of PHP Objects

后端 未结 5 1374
孤城傲影
孤城傲影 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:16

    Yes.

    $array[] = new stdClass;
    $array[] = new stdClass;
    
    print_r($array);
    

    Results in:

    Array
    (
        [0] => stdClass Object
            (
            )
    
        [1] => stdClass Object
            (
            )
    
    )
    

提交回复
热议问题