Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php count occurrences of string in array

$array = array('', '', 'other', '', 'other');

$counter = 0;
foreach($array as $value)
{
  if($value === '')
    $counter++;
}
echo $counter;
Comment

php count string in array


<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
var_dump(count($a));

$b[0]  = 7;
$b[5]  = 9;
$b[10] = 11;
var_dump(count($b));

var_dump(count(null));

var_dump(count(false));
?>
  /* result
  
  
int(3)
int(3)

Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12 // as of PHP 7.2
int(0)

Warning: count(): Parameter must be an array or an object that implements Countable in … on line 14 // as of PHP 7.2
int(1)

*/

Comment

PREVIOUS NEXT
Code Example
Php :: magento2 move Exception #0 (Exception): Notice: Undefined offset: 2 in /var/www/nucleus/htdocs/vendor/magento/framework/Encryption/Encryptor.php on line 591 
Php :: wordpress limit post content length 
Php :: PDO encode result recordset to utf8 
Php :: json_encode() 
Php :: how to use attempt in laravel 
Php :: laravel 8 seeding 
Php :: acf looping through post types 
Php :: alert message in blade template with() 
Php :: laravel copy row 
Php :: if is page woocommerce 
Php :: active page in laravel 
Php :: laravel import data from csv 
Php :: return redirect to extranal url in laravel 
Php :: laravel pluck 
Php :: codeigniter sanitize input field 
Php :: how to setup cron job for laravel queues on shared hosting 
Php :: update laravel 7 to 8 
Php :: PHP strrpos — Find the position of the last occurrence of a substring in a string 
Php :: rendering json in laravel 
Php :: woocommerce view order details frontend with shortcode 
Php :: error pdo php Exception 
Php :: laravel collection when 
Php :: Laravel (8) - Routing to controller with optional parameters 
Php :: php lcfirst 
Php :: laravel check if environment is production 
Php :: variables in php 
Php :: WordPress Plugin Definition 
Php :: php json pretty print and slash 
Php :: htaccess new date timestamp 
Php :: laravel call controller method from another controller 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =