Jump to content

How to count occurences...


Rita_Ruah

Recommended Posts

Hello, I have a programming doubt... I think this can apply to every language, imagine this scenario where I have this xml:

 

<MediaFiles>
<MediaFile>
   <![CDATA[VIDEO]]>
</MediaFile>
<MediaFile>
   <![CDATA[VIDEO]]>
</MediaFile>
<MediaFile>
   <![CDATA[VIDEO]]>
</MediaFile>
<MediaFile>
   <![CDATA[VIDEO]]>
</MediaFile>
<MediaFile>
   <![CDATA[VIDEO]]>
</MediaFile>
</MediaFiles>
 
How can I count the number of occurences of <MediaFile> so I can make a group of every mediafile and do a Random to select one of them?
 
Pseudo-code of what I want:
 
foreach(<mediafile> of <mediafiles>)
array[] = mediafile VIDEO;
 
Can you give me an example of php and other for JS? 
 
Thanks.
 
Link to comment
https://forums.phpfreaks.com/topic/281067-how-to-count-occurences/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.