2
I have an Object returned from the Facebook API and would like to "Count" the reactions of a post.
I have this excerpt from the code:
// Descodificando o JSON
$objeto = json_decode($userNode['reactions']);
// Percorrendo dados
foreach( $objeto as $tipo )
{
echo $tipo->type."<br />";
}
PS: var_dump($objeto);
array (size=6)
0 =>
object(stdClass)[115]
public 'id' => string '753855038121014' (length=15)
public 'name' => string 'Ivone Kodama' (length=12)
public 'type' => string 'LIKE' (length=4)
1 =>
object(stdClass)[113]
public 'id' => string '392780707772557' (length=15)
public 'name' => string 'Eunice Garcez' (length=13)
public 'type' => string 'LIKE' (length=4)
2 =>
object(stdClass)[114]
public 'id' => string '1355251021162174' (length=16)
public 'name' => string 'Gih Andrea Anastacio De Carvalho Baracat' (length=40)
public 'type' => string 'SAD' (length=3)
3 =>
object(stdClass)[54]
public 'id' => string '408046949554084' (length=15)
public 'name' => string 'Terezinha Piassa' (length=16)
public 'type' => string 'LIKE' (length=4)
4 =>
object(stdClass)[51]
public 'id' => string '194465404377613' (length=15)
public 'name' => string 'Sueli Aparecida' (length=15)
public 'type' => string 'LIKE' (length=4)
Return me the following:
WOW
WOW
LIKE
LIKE
HAHA
WOW
LIKE
LIKE
SAD
LIKE
LIKE
HAHA
Etc... How can I "know" how often the word is repeated LIKE for example ?
If it is an array (
$objeto->type
) can do so: Find duplicate values in an array– rray
@rray not understood, could be a little more clear? Thank you
– user50712
You can take the array that has these values and use the function
array_count_values()
it will return the number of times the words appeared. Just need to know exactly what is the key of the array/object to apply.– rray
@rray look at the issue please.
– user50712
@Only take the left-hand print: https://imageshack.us/i/pmmeNF0Gp
– user50712