PHP array sorting problem

WBOY
Release: 2016-07-06 13:51:16
Original
903 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

Why does Dog A appear repeatedly?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template