Re: [PHP] Searching and Count within array

2005-07-26 Thread Jochem Maas

Rasmus Lerdorf wrote:

array_count_values()

Bagus Nugroho wrote:


Hi Master,


not sure what Bagus was intending with 'Master',
regardless, the reply made me smile...

:-)



I have an array as : 
$myArray = array('four','four','four','four','one,,'three','three','three','two','two'); 


bla /

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Searching and Count within array

2005-07-25 Thread Bagus Nugroho
Hi Master,
 
I have an array as : 
$myArray = 
array('four','four','four','four','one,,'three','three','three','two','two'); 
 
Then I want output like this, 
//==
four is 4 times
three is 3 times
two is 2 times
one is 1 times //(it 's better if one is 1 time).
//===
 
How can I search and count the array? Or better search and count directly using 
MySQL API?
 
Note : array was generated from MySQL DB
//==
?php
$connection = mysql_connect(localhost,user,pass);
mysql_select_db(ecd);
$result = mysql_query(SELECT * FROM pre_main ORDER BY mDate DESC LIMIT 
20,$connection);
while ($row = mysql_fetch_row($result)) {
$myArray[] = $row[0];
}
   sort ($myArray);//sorting array
//result : $myArray = 
array('two','two','three','three','three','four','four','four','four','one');

?
//=
 
Thanks in advance
 


Re: [PHP] Searching and Count within array

2005-07-25 Thread Rasmus Lerdorf
array_count_values()

Bagus Nugroho wrote:
 Hi Master,
  
 I have an array as : 
 $myArray = 
 array('four','four','four','four','one,,'three','three','three','two','two'); 
  
 Then I want output like this, 
 //==
 four is 4 times
 three is 3 times
 two is 2 times
 one is 1 times //(it 's better if one is 1 time).
 //===
  
 How can I search and count the array? Or better search and count directly 
 using MySQL API?
  
 Note : array was generated from MySQL DB
 //==
 ?php
 $connection = mysql_connect(localhost,user,pass);
 mysql_select_db(ecd);
 $result = mysql_query(SELECT * FROM pre_main ORDER BY mDate DESC LIMIT 
 20,$connection);
 while ($row = mysql_fetch_row($result)) {
 $myArray[] = $row[0];
 }
sort ($myArray);//sorting array
 //result : $myArray = 
 array('two','two','three','three','three','four','four','four','four','one');
 
 ?
 //=
  
 Thanks in advance
  
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php