0

$a=E;$b=D;$c=E;$d=A; So I want to count how many 'E' or 'D' or 'A'? Is this possible to perform this coding?

Help me.

1 Answer 1

1

Use array_count_values function

$a='E';
$b='D';
$c='E';
$d='A';

$values = array($a, $b, $c, $d);

$vals = array_count_values($values);
print_r($vals); // Array ( [E] => 2 [D] => 1 [A] => 1 )
Sign up to request clarification or add additional context in comments.

2 Comments

Then how to store the vale of 'E' i.e. 2 in a new variable? Actually I want to find out number of 'E' and store the value in a new variable.
as you see the result of array_count_values($values) is an array, so you can make a loop with foreach and get the keys and values for each element.

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.