N
N
newaitix2016-03-08 23:38:32
PHP
newaitix, 2016-03-08 23:38:32

How to find the number of rows in an array?

array(
    'a'=>'b'
    'b'=>'c'
    'c'=>'d'
    'd'=>'e'
    'e'=>'f'
    'f'=>'g'
    );

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Ernest Faizullin, 2016-03-08
@newaitix

$arr = array(
    'a'=>'b'
    'b'=>'c'
    'c'=>'d'
    'd'=>'e'
    'e'=>'f'
    'f'=>'g'
    );

echo count($arr);

if you need the number of exactly string values, then:
function count_strings($array) {
  $count = 0;
  foreach ($array as $item) {
    if (is_string($item))
      $count++;
  }
  
  return $count;
}

P
Pavel Volintsev, 2016-03-08
@copist

php.net/manual/en/function.count.php

D
Dmitry, 2016-03-09
@thewind

sizeOf is faster than count

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question