1

I would like to know how to tell the value of an array or json. Example: I want to count the value of the item GRUPO_OK = SIM and MRS_central = 1001.

Output:

MRS_central: "1001" => 2 GRUPO_OK: "SIM" => 3

Example array

Array ( [data] => Array ( [0] => Array ( [MRS_central] => 1003 [MRS_ipsat] => [GRUPO_OK] => NÃO ) [1] => Array ( [MRS_central] => 1001 [MRS_ipsat] => [GRUPO_OK] => SIM ) [2] => Array ( [MRS_central] => 1001 [MRS_ipsat] => [GRUPO_OK] => SIM ) [3] => Array ( [MRS_central] => 1002 [MRS_ipsat] => 10.4.0.253 [GRUPO_OK] => SIM ) ) )

Example json

{
data: [
{
MRS_central: "1001",
MRS_ipsat: "",
GRUPO_OK: "SIM"
},
{
MRS_central: "1001",
MRS_ipsat: "",
GRUPO_OK: "SIM"
},
{
MRS_central: "1003",
MRS_ipsat: "",
GRUPO_OK: "SIM"
},
{
MRS_central: "1002",
MRS_ipsat: "10.4.0.253",
GRUPO_OK: "NÃO"
}
]
}
1

1 Answer 1

0

If you have array_column(), you can extract each column. Then, you can use array_count_values() to count how many times a value appears in an array.

$mrs_grupo = array_column($arr['data'], 'GRUPO_OK');
$count = array_count_values($mrs_grupo);

print_r($count);


//RESULT
array(2) {
  ["SIM"]=>
  int(3)
  ["NÃO"]=>
  int(1)
}
Sign up to request clarification or add additional context in comments.

Comments

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.