GridView - compare a external variable in closure from colum value

I have a gridview with a ArrayDataProvider. I want compare a external variable in closure from colum value:


<?php echo GridView::widget([

                        'dataProvider'      => $dataProvider,

                        'summary' => false,

                        'columns' => [

                            [

                                'class' => 'yii\grid\SerialColumn',

                            ],                           

                            [   

                                'attribute' => Yii::t('app','Adsense CTR'), 

                                'format'    => 'raw',

                                'value'     => function($data){

                                    if($data['ga:adsenseCTR'] >= $externalVariable){

                                        $class = 'alert-success';

                                    } else {

                                        $class = 'alert-danger';

                                    }

                                    return Html::tag('span', $data['ga:adsenseCTR'], ['class'=>$class]);

                                } 

                            ]

                        ]


                    ]); ?>

how do this?

Have you tried with:




'value'     => function($data) use ($externalVariable) {



Thank you, Fabrizio. Work’s fine!