public
Created

associative arrays from php.net karma system

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.