2

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

4 Answers 4

11

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

Sign up to request clarification or add additional context in comments.

Comments

10

There is count function.

Comments

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.