Answer the question
In order to leave comments, you need to log in
Split array with newline for select?
Good afternoon, tell me please.
There is an array
It is
necessary to break into lines and display in select.
Each line, a separate option item in select
The code itself:
$result = array();
$line = $new_info->city_countruies; //Moscow Saint-petersburg Krasnodar (с новой строки)
$ar = explode("\n",$line);
foreach($ar as $arr){
$lin = explode("\n",$arr);
$result = $arr;
}
$delivery->city = $result; // Вывод
<select class="form-control" name="country">
<option value="">{$delivery->city|escape}</option>
</select>
Answer the question
In order to leave comments, you need to log in
You are overwriting $result on each iteration here, so it outputs the last element
foreach($ar as $arr){
$lin = explode("\n",$arr);
$result = $arr; //ошибка
$result[] = $arr; //добавление нового элемента в массив
}
In the template, the output must be done through a loop:
Smarty foreach
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question