Mark Pelillo wrote:

> I am a Newbie at PHP
>
> I am sure I am missing something small but...
>
> I am trying to create a form selection box which an alphabetically sort
> list of a unix group file.
>
> The group file has the format groupname::groupnumber:
>
> I have tried to create an array using the array=fgetcsv($fp, 30, ":")
> which does read each line of the file.  I have used this line in a while
> loop and also a for loop, but everytime I exit the loop, the array now
> has no information.
>
> I found if the change the line to be array[]=fgetcsv($fp, 30, ":") then
> I can exit the loops but now how do extract only the group names from
> the array and be able to sort them.
>
> Ideally what I would like to do is create an array where the keys =
> group number and value = groupname. I need to be able to natsort the
> values and display in the selection form box.

Well lets try....
<?php
$OutputArray = array(); //Create an array to the output
$fp = fopen ("yourgroupfile","r");  //Open the groupfile
while ($d = fgetcsv ($fp, 1000, ":")) { //While loop as long there is some
data
    $OutputArray[$d[2]] = $d[0];  //Set groupid as key, and groupname as
value
} //end of while
fclose ($fp); //close file
print_r($OutputArray); //Print out the array, to check the values!
?>

Please reply if this doesn't work?
By the way... if you got further problems, please tell us which version of
PHP you use.....

Regards,

Johan Holst Nielsen
www.weknowthewayout.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to