简体   繁体   中英

php: i have 5 array, how can i make them as one?

    foreach($archive as $archrow){
        echo $archrow->doc_name;   //document name
        echo $archrow->doc_status; //document status
    }

    foreach($arc as $arcrow){
        echo $arcrow->fullname; //Author
    }

    foreach($pos as $posrow){
        echo $posrow->position_name;  //position

    }

    foreach($loc as $locrow){

        echo $locrow->location;  //Department
    }

i would like to make a table and arrange them by category like this:

________________________________________________________________________________

|Document name | Author | Position | Department | Document Status |


| asdasd | john | Manager | Acct | adsads |

I want to assume you want extract one element form each array at the same time

You can try

$mi = new MultipleIterator(MIT_NEED_ANY|MIT_KEYS_NUMERIC);
$mi->attachIterator(new ArrayIterator($archive), 'achive');
$mi->attachIterator(new ArrayIterator($arc), 'arc');
$mi->attachIterator(new ArrayIterator($pos), 'pos');
$mi->attachIterator(new ArrayIterator($loc), 'loc');

echo "<pre>";
foreach ( $mi as $member ) {
    echo $member['achive']->doc_name, "|", $member['achive']->doc_status, "|", $member['arc']->fullname, "|", $member['pos']->position_name, "|", $member['loc']->position_name ,PHP_EOL;
}

If you want to merge arrays you can use array_merge for that: http://www.php.net/manual/en/function.array-merge.php
But your example isn't an array...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM