-1

Supposing I have this array:

Array
(
    [Europa] => Array
        (
            [country] => France
            [capital] => Paris
        ),
        (
            [country] => Spain
            [capital] => Madrid
        )
    [Asia] => Array
        (
            [country] => Russia
            [capital] => Moscow
        )
)

How can I count to number of item containing in Asia or Europa`?

Thanks.

2

2 Answers 2

0

Assuming

  $myArray= [
    'Europa' => [
            'country' => France
            'capital' => Paris
        ],
        [
            'country' => Spain
            'capital' => Madrid
        ],
    'Asia' => [
            'country' => Russia
            'capital' => Moscow
        ],
  ];

you could use count() based on index

$numEuropa = count($myArray['Europa']);
$numAsia = count($myArray['Asia']);
Sign up to request clarification or add additional context in comments.

Comments

0

Use count in array_map as:

$cnts = array_map("count", $array);

Or with loop:

foreach($array as $key => $val)
    echo $key . " count is: " . count($value);

Live example: 3v4l

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.