-
-
Save flagoworld/5754891 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ARRAY IN: | |
$in=array( | |
array('name' => 'john', 'occupation' => 'electrician'), | |
array('name' => 'jack', 'occupation' => 'plumber'), | |
array('name' => 'jake', 'occupation' => 'office rat'), | |
array('name' => 'pete', 'occupation' => 'electrician') | |
); | |
//ARRAY OUT: | |
/* | |
array( | |
'electrician' => array('john', 'pete'), | |
'plumber' => array('jack'), | |
'office rat' => array('jake') | |
); | |
*/ | |
$out=array(); | |
foreach($in as $val) | |
{ | |
if(!isset($out[$val['occupation']])&&!is_array($out[$val['occupation']])) | |
$out[$val['occupation']]=array(); | |
$out[$val['occupation']][]=$val['name']; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment