-1

I try to assign the value to my array of object

$models = [new Form()];

    for ($i=0;$i<3;$i++){
        $models[$i]->title = $i;
    }

when I try I got error

Creating default object from empty value

So How can I assign the value more than $models[0]?

Thanks.

0

1 Answer 1

1

I solve this by

$models = [];

for ($i=0;$i<3;$i++){
    $models[$i] = new Form();
    $models[$i]->title = $i;
}

Thanks @castis.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.