Click to See Complete Forum and Search --> : Need Help With Arrays in PHP


GonzoTheHorrible
10-29-2001, 03:17 AM
Hello all. line 2 sets the file I want to get permission of. line 3 returns the uid of the fileowner.
//Trouble starts//
line 4 returns an asscoiative array w/ info about user referenced by uid. LINE 5 WOULD LIKE TO RETURN THE HUMAN READABLE NAME OF THIS USER.
// Trouble ends //


// Understanding ARRAYS
$file="/home/jason/ftp.php";
$uid = fileowner( $file );
$humanuid = posix_getpwuid( $uid );
$humanuid[NAME] = $name;

echo "$name\n";
echo "$uid\n";

The Output is:
X-Powered-By: PHP/4.0.6
Content-type: text/html

501

The PHP manual has a table of "user info elements" so I'm guessing that saying $humanuid[NAME] = $name
would return the users name funny enough. However it isn't. Could anyone tell me what I'm missing or not understanding or point me in the right direction??? Any help would be much appriech.Thanks in advance.

Stuka
10-29-2001, 12:43 PM
Lemme see...$humanuid[NAME] is the value you want from the $humanuid array, correct? And you want that assigned to $name, right? Shouldn't the assignment line be:$name = $humanuid[NAME];

GonzoTheHorrible
10-29-2001, 03:49 PM
Most likely. However, I wasen't aware that the order made the difference. Saying

$X = "string" or int;

would be the same as saying?

"string" or int = $X;

Outside of my skewed syntax, is accessing this value correct?? Limited programming knowledge doesn't help eh ;)?? What I'm really confused about is, knowing how to reference the value returned by the array. I assumed that you'd use the value from table in the manual to access that value. Or am I wrong?? Otherwise, how would I know??

Stuka
10-29-2001, 06:19 PM
OK, simple lesson for C-like languages (C, C++, Java, PHP, Perl, others I'm sure):
$x = $name assigns the value in name to the variable x. $name = $x assigns the value in x to the variable name. As to your specific problem, I think that's all there is - $name = $humanuid[name] should do the trick - note though, that the 'name' part is lower case (which the PHP docs show, and this IS case-sensitive).

GonzoTheHorrible
10-29-2001, 11:25 PM
Thank you Stuka. Got it by simply saying
echo "$humanuid[name]";
w/ name in LOWERCASE! Tried
$name = $humanuid[name]; then echoing $name
and
$humanduid[name] = $name; then echoing $name
to no avail.
Wierd. I do know more now than I did know when I posted and for that I say thanks :D

Stuka
10-30-2001, 11:04 AM
Glad you got it working - but it seems odd that $name=$humanuid[name] didn't work - oh well...