$count = array(1 => 'one', 2 => 'two', 3 => 'three', 4=>'');
配列には4つの値があり、1つのキーには値がありません。どのキーに値がある配列を数えるか?
キーに値がある配列の数を表示したいと思います。
$count = array(1 => 'one', 2 => 'two', 3 => 'three', 4=>'');
配列には4つの値があり、1つのキーには値がありません。どのキーに値がある配列を数えるか?
キーに値がある配列の数を表示したいと思います。
使用array_filter
$array = array(1 => 'one', 2 => 'two', 3 => 'three', 4=>'');
$count = count(array_filter($array));
echo $count;
、これを試してみて、その値
print_r(array_filter($count, create_function('$value', 'return $value !== "";')));
//Use functions array_filter() and count()
$fullarray = array(1 => 'one', 2 => 'two', 3 => 'three', 4=>'');
$filteredArray = array_filter($fullarray);//filters the values of an array using a callback function
$count=count($filteredArray);//returns the number of elements in an array.
print_r($count);//display count
'array_filter()' –
私は=> ' '3を推測している空ではないすべてのキーをフィルタリング'three'はタイプミスですか? – Tom