Home > Article > Backend Development > PHP array sorting problem
The following is a demo two-digit array. The number of arrays in $arr is not fixed. Want to generate results like the one below.
That is, each array in $arr is intersected and combined.
<code>$arr = array( array('豪华1','海边2'), array('狗A','狗B'), array('1小时','2小时','3小时') ); </code>
The following is a demo two-digit array. The number of arrays in $arr is not fixed. Want to generate results like the one below.
That is, each array in $arr is intersected and combined.
<code>$arr = array( array('豪华1','海边2'), array('狗A','狗B'), array('1小时','2小时','3小时') ); </code>
<code>function output($array, $lead = '') { $items = current($array); $subArray = array_slice($array, 1); foreach($items as $item) { if ($subArray) { output($subArray, $lead . $item . '-'); } else { echo $lead . $item . '\n'; } } } </code>
Why does Dog A appear repeatedly?