Reputation: 13
Array
(
[0] => Array
(
[name] => WWW
)
[1] => Array
(
[name] => Hi
)
[2] => Array
(
[name] => Hello
)
[3] => Array
(
[name] => World
)
)
I have the above array and I want to count the number of keys.
When using the following code
$temp = array_keys($array);
echo $temp;
the result is 2 instead of 4 (0,1,2,3). What I'm doing wrong ?
Upvotes: 1
Views: 204
Reputation: 964
Very simple buddy. Look this:
$array = array(0 => 100, "color" => "red");
print_r(count($array));
php.net help you for all! ;)
Upvotes: -1
Reputation: 219938
Just count the array itself: count($array)
.
There's always the same amount of keys as there are values!
Upvotes: 4
Reputation: 1136
You need to count the array in order to get a number:
$arr = array
(
"0" => array
(
"name" =>"WWW"
),
"1" => array
(
"name" => "Hi"
),
"2" => array
(
"name" => "Hello"
),
"3" => array
(
"name" => "World"
)
);
$keys_count = count($arr);
echo $keys_count;
Upvotes: 4