**Пытался следующим образом:** *1-й способ:* function lite_list_array($array){ echo '<ol>'; foreach($array as $value){ echo '<li>'; echo $value.' '.'<br>'; echo '</li>'; if(is_array($value)){ echo '<ol>'; foreach($value as $value2){ echo '<li>'; echo $value2.' '.'<br>'; echo '</li>'; if(is_array($value2)){ echo '<ol>'; foreach($value2 as $value3){ echo '<li>'; echo $value3.' '.'<br>'; echo '</li>'; } echo '</ol>'; } } echo '</ol>'; } } echo '</ol>'; } *2-й способ:* function list_array($array) { echo "<ol>"; foreach ($array as $value){ echo "<li>"; if (is_array($value)){ list_array($value); } else { echo $value; } echo "</li>"; } echo "</ol>"; } |
1 answer
When you walked through a regular foreach array, you did not try to check via if what is contained in the variable that foreach now processes in the current loop? For example, if a string, then do $ url. "" ;, and if there is an array, then make the processing inline foreach loop. For example:
$arr = array('a','b','c',array('d','e','f','g'),'h','j',array('k',array('l','q')),'w'); $cycle = 0; foreach ($arr as $bolt){ if(is_array($bolt) === true){ foreach($bolt as $param){ if(is_array($param) === true){ foreach($param as $pris){ echo '____'.$cycle.'. '.$pris."</br>"; }} else{ echo '__'.$cycle.'. '.$param."</br>";} } }else { echo $cycle.'. '.$bolt."</br>"; $cycle++; } } Something like this can be tried. The enumeration variable itself can be replaced with an array of letters and then just make for each item a selection of a new succeeding element with unit per element at the end of the current iteration.
- modified the code a bit to work correctly with the nested array after k. The only thing you need is to make the list instead of double underscores. - Mastas
|
