tags:

views:

446

answers:

4

Can I check the number of values in an array, for example...

$abc=array();

$abc[0]="asd";
$abc[1]="sadaf";
$abc[2]="sfadaf";

I want to check and store it(2) in a variable that array abc[] exists till $abc[2]..

Thanks

+10  A: 

There is count function.

empi
+7  A: 

Use count or sizeof for the total number of values or array_count_values to count the frequency of each value.

Gumbo
A: 
$arraysize = sizeof($abc) - 1; // will be set to 2
if(isset($abc[$arraysize]))
{
   $abcEndExists = true;
}
else
{
    $abcEndExists = false;
}
Nikko
A: 

Is this what you're looking for?

$minArrayIndex  = 2;
$arrayCountTest = ((count($abc) - 1) >= $minArrayIndex) ? true : false;

This will assign $arrayCountTest true if the array has elements of at least an index of 2.

Kieran Hall