-1

I`ve seen the following notation here: http://www.php.net/manual/en/features.http-auth.php

What is

($users[$data['username']] 

for?

Is it array and sub array?

Would you please give me a clear example

Thanks

Ayad Mfs
  • 33
  • 5
  • $users is an array and $data['username'] is a value from the array $data. The code you posted is retrieving the value of $users with the index value of $data['username']. – noko Aug 22 '12 at 23:20

3 Answers3

2

You should think of it like this:

$username = $data['username'];
$user = $users[$username];

It uses the value from $data['username'] as a key in $users to find a particular user record.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
1

$data['username'] is just key for assocative array

$data = Array(
  'username' => 'george';
);
$users = Array(
  'george' => "George Clooney",
  'angelina' => "Angelina Jolie"
);

echo $users['george']; // George Clooney
echo $users['angelina']; // Angelina Jolie
echo $users[$data['username']]; // George Clooney
echo $data['username']; // george
Peter
  • 16,453
  • 8
  • 51
  • 77
1

$users is an associate array (see the declaration). $data['username'] is the key used to extract a specific value from that array.

Sujith Surendranathan
  • 2,569
  • 17
  • 21