Count items with a certain extension within an array in PHP

-1

Hello, good morning! It's OK?   I need to mount a media gallery for a certain image extension ('.jpg') and I am having difficulty counting the files ($ key) in the value field (ds_midia_link).   How should I proceed?

Thank you in advance,

[media] = > SimpleXMLElement Object         (             [media] = > Array                 (                     [0] = > SimpleXMLElement Object                         (                             [image_id] = > 5a29842d8ec9f                             [ds_imagem_credi] = > Google                             [ds_image] = > black Panther                             [ds_imagem_link] = > link

                [1] => SimpleXMLElement Object
                    (
                        [id_imagem] => 5a29842d8ec9f
                        [ds_imagem_credi] => Google
                        [ds_imagem] => Pantera 
                        [ds_imagem_link] => http://portal.interno.com.br//_midias/jpg/exemplo1.jpg

                [2] => SimpleXMLElement Object
                    (
                        [id_imagem] => 5a29842d8ec9f
                        [ds_imagem_credi] => Google
                        [ds_imagem] => Pantera 
                        [ds_imagem_link] => http://portal.interno.com.br//_midias/jpg/exemplo2.jpg
    
asked by anonymous 08.12.2017 / 13:49

1 answer

0

There is a function in php that counts count() . Assign the value to a variable eg $qtdReg = count($seuArray);

Ref: link

<?php

$arr = [
        [
            'id_imagem' => '5a29842d8ec9f',
            'ds_imagem_credi' => 'Google',
            'ds_imagem' => 'Pantera',
            'ds_imagem_link' => 'http://portal.interno.com.br//_midias/jpg/exemplo1.jpg'
        ],
        [
            'id_imagem' => '5a29842d8ec9f',
            'ds_imagem_credi' => 'Google',
            'ds_imagem' => 'Pantera',
            'ds_imagem_link' => 'http://portal.interno.com.br//_midias/jpg/exemplo2.jpg'
        ],
];

$qtdReg = count($arr);

echo $qtdReg;

The output will be: 2

    
08.12.2017 / 13:54