Hi again
The following gridColumn array is used for a gridview widget:
<?php
$propertyId = [];
$gridColumn = [
[
'attribute' => 'serial',
'label' => '#',
'format' => 'raw',
'value' => function ($m, $k, $i) use ($propertyId) {
print_r($propertyId);
if (!array_key_exists($m->id, $propertyId)) {
$id = $i + 1;
$key = $m->id;
$propertyId[$key] = &$id;
} else {
$id = $propertyId[$m->id];
}
print_r($propertyId);
$r = '<div class="markerNumber" style="cursor: pointer;" data-id="' . $m['id'] . '">'
. '<span class="badge badge-pill badge-primary">'
. $id
. '</span>'
. '</div>';
return $r;
}
],
The last print_r show single arrays
Array ( [9] => 1 ) Array ( [10] => 2 ) Array ( [10] => 3 ) Array ( [10] => 4 ) Array ( [10] => 5 )
the fist, nothing. I suggest the elements will be insert by reference due to the fact that after the inner function is finished, the array element is forgotten.
How can avoid that the array elements are missing?
Thanks and best regards,
Toby