S
S
Sergey Beloventsev2016-10-31 23:29:08
Yii
Sergey Beloventsev, 2016-10-31 23:29:08

Why doesn't array_filter work?

here is the code instead of a thousand code
var_dump($model-image);
I get

object(common\models\Image)#2028 (9) { 
    ["class"]=> NULL 
    ["_attributes":"yii\db\BaseActiveRecord":private]=> array(13) {
      ["title_alt"]=> string(46) "Ложное обвинение (сериал)" 
      ["path"]=> string(15) "serial/2016/10/" 
      ["name"]=> string(10) "979247.jpg" 
      ["for_home"]=> int(1) }  
    }

then I do this
$img = array_filter($model->image, function($item) {
                    return $item->for_home == 1;
                });
    var_dump($img)

I get null. Why am I not getting the object? in $img

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-11-01
@Sergalas

For some reason, it seems that you are passing an object to array_filter and not an ARRAY of objects

S
Snewer, 2016-10-31
@Snewer

var_dump($image) why $image and not $img?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question