Skip to content

Instantly share code, notes, and snippets.

@Tyrael
Created June 14, 2011 12:12
Show Gist options
  • Save Tyrael/1024786 to your computer and use it in GitHub Desktop.
Save Tyrael/1024786 to your computer and use it in GitHub Desktop.
associative arrays from php.net karma system
<?php
$url = 'http://svn.php.net/viewvc/SVNROOT/global_avail?revision=HEAD&view=co';
$file = file_get_contents($url);
$avail_lines = array();
$pattern = '/^avail\|(.*?)\|(.*?)$/sm';
$repos = array();
$users = array();
preg_match_all($pattern, $file, $avail_lines);
foreach($avail_lines[0] as $i => $line){
$line_users = explode(',', $avail_lines[1][$i]);
$line_repos = explode(',', $avail_lines[2][$i]);
foreach($line_repos as $repo){
if(!isset($repos[$repo])){
$repos[$repo] = array();
}
}
foreach($line_users as $user){
foreach($line_repos as $repo){
$repos[$repo][] = $user;
$users[$user][] = $repo;
}
}
}
var_dump($users);
var_dump($repos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment