note 97109 added to function.array-combine
| From: | bradentkeith at dot dontspam dot gmail dot com | Date: | Thu, 01 Apr 2010 20:20:01 +0000 |
| Subject: | note 97109 added to function.array-combine | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167630@lists.php.net to get a copy of this message | ||
I needed a function that would take keys from one unequal array and combine them with the values of
another. Real life application:
Select 4 product types.
Each product has a serial.
There are 4 sets of products.
<?php
function array_combine2($arr1, $arr2) {
$count1 = count($arr1);
$count2 = count($arr2);
$numofloops = $count2/$count1;
$i = 0;
while($i < $numofloops){
$arr3 = array_slice($arr2, $count1*$i, $count1);
$arr4[] = array_combine($arr1,$arr3);
$i++;
}
return $arr4;
}
?>
Input:
Array
(
[0] => SMART Board
[1] => Projector
[2] => Speakers
[3] => Splitter
)
, Array
(
[0] => serial to smart board1
[1] => serial to projector 1
[2] => serial to speakers 1
[3] => serials to splitter 1
[4] => serials to smart board 2
[5] => serials to projector 2
[6] => serials to speakers 2
[7] => serials to splitter 2
)
Array
(
[0] => Array
(
[SMART Board] => serial to smart board1
[Projector] => serial to projector 1
[Speakers] => serial to speakers 1
[Splitter] => serials to splitter 1
)
[1] => Array
(
[SMART Board] => serials to smart board 2
[Projector] => serials to projector 2
[Speakers] => serials to speakers 2
[Splitter] => serials to splitter 2
)
)
----
Server IP: 69.147.83.197
Probable Submitter: 70.60.193.155
----
Manual Page -- http://www.php.net/manual/en/function.array-combine.php
Edit -- https://master.php.net/note/edit/97109
Del: integrated -- https://master.php.net/note/delete/97109/integrated
Del: useless -- https://master.php.net/note/delete/97109/useless
Del: bad code -- https://master.php.net/note/delete/97109/bad+code
Del: spam -- https://master.php.net/note/delete/97109/spam
Del: non-english -- https://master.php.net/note/delete/97109/non-english
Del: in docs -- https://master.php.net/note/delete/97109/in+docs
Del: other reasons-- https://master.php.net/note/delete/97109
Reject -- https://master.php.net/note/reject/97109
Search -- https://master.php.net/manage/user-notes.php