Home > Backend Development > PHP Tutorial > PHP array sorting problem

PHP array sorting problem

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:51:16
Original
954 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template