A
A
ajky2016-09-06 09:35:26
Yii
ajky, 2016-09-06 09:35:26

How to remove a value from an object in Yii2?

There is an object where $this->text is an array, how to remove one of the array value?
unset($this->text[100500]) doesn't work,
PS this action happens in beforeValidate.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2016-09-06
@ajky

You are trying to modify an overloaded property. Create a new variable:

$array = $this->text;
unset($array[100500]);
$this->text = $array;

N
Nikolai Konyukhov, 2016-09-06
@heahoh

If there is a setter then try $this->text[100500] = null

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question