A
A
Anton2018-07-24 14:34:03
PHP
Anton, 2018-07-24 14:34:03

How to create an array from while values?

Now the page has this code:

$aBitrixParamsID = Array(
"Зеленый" => "2014",
"Синий" => "2015",
"Красный" => "2048",
"Белый" => "2016", 
// и еще 100 всяких цветов с id-шниками
);

I want to replace it so that each time I don’t enter new colors into it, for this I wrote the following code, which will display all available colors with their id:
while($ar_fields = $my_slider->GetNext())
{
echo $ar_fields['PROPERTY_COLOR_VALUE']; //выведет Зеленый, Синий, Зеленый, Белый, Белый....
echo $ar_fields['PROPERTY_COLOR_ENUM_ID']; //выведет 2014, 2015, 2014, 2016, 2016.....
}

And I don’t know how to proceed further:
You need to remove the repetitions and write them to the $aBitrixParamsID array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-07-24
@anton99zel

Not?

$colors = [];
while($ar_fields = $my_slider->GetNext()) {
  $colors[$ar_fields['PROPERTY_COLOR_ENUM_ID']] = $ar_fields['PROPERTY_COLOR_VALUE'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question