0

I'm trying to find the number of occurrences of these ([0],[1],[2] etc) in an array but I can't seem to get it to work.

Here's what I'm trying at the moment to output the result:

$photos = (my entire array)
$p = $photos['photos']['photo'];
$max = (max($p));
echo $max;

And here's how my array looks under print_r:

Array
(
    [photos] => Array
        (
        [example1] => 1
        [example2] => 1
        [photo] => Array
            (
                [0] => Array
                (
                        [id] => 726462325
                        [owner] => 985275329856
                )   
                [1] => Array
                (
                        [id] => 836252653
                        [owner] => 736053268937
                )        
                etc
2
  • 3
    Can you be more specific, you're trying to count the number of occurrences of what exactly? Commented Feb 16, 2012 at 18:48
  • Sorry, I'm looking for the number of arrays inside the photo array. Commented Feb 16, 2012 at 18:51

2 Answers 2

1

As @Ryan mentioned, you need to use the count() function. This is how you would use it in your example:

$photos = (my entire array)
$p = $photos['photos']['photo'];
$count = count($p);
Sign up to request clarification or add additional context in comments.

Comments

1

I think you're looking for the count() function.

Good luck!

1 Comment

The solution usually is! Glad to help

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.