Home  >  Article  >  Backend Development  >  PHP array sorting problem

PHP array sorting problem

WBOY
WBOYOriginal
2016-07-06 13:51:16906browse

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>

PHP array sorting problem

Reply content:

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>

PHP array sorting problem

<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?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn