user796443
user796443

Reputation:

how to get key-value in associative array?

I've an associative array:

Array ( [1] => 1 [2] => 0 )

array will always contain only two.

The key is user_id and value is status.

I applied ksort() to the array, because I wanted lower user_id first in the array.

Now I want to grab key and value for each, (but I never know what key=user_id is):

$key_1
$value_1
$key_2
$value_2

Upvotes: 0

Views: 105

Answers (3)

Vladislav Rastrusny
Vladislav Rastrusny

Reputation: 30013

foreach ($myArray as $key => $value) {
   .......
}

Upvotes: 2

vara
vara

Reputation: 836

keys=array_keys($array);
values=array_values($array);

Upvotes: 0

mas.morozov
mas.morozov

Reputation: 2736

reset($array);
list($key_1, $value_1) = each($array);
list($key_2, $value_2) = each($array);

Upvotes: 0

Related Questions