Jump to content

[SOLVED] php array help


2levelsabove

Recommended Posts

hello,

 

I have an array that contains the following data.

 

10/31/08*10/31/08*10/31/08*10/31/08*10/31/08*10/31/08*10/30/08/*10/30/08

 

for graphing purposes i need to get information like 10/31/08 = 6  visits

                                                                    10/30/08 = 2 visits

 

what would be the best way ? I am trying to build my own traffic graph

 

 

thanks :)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/130884-solved-php-array-help/
Share on other sites

<?php
  $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08');
  $data = array();
  foreach($array as $item){
    if(is_array($data[$item]))
      $data[$item]++;
    else
      $data[$item] = 1;
  }
  print_r($data);
?>

my bad...

<?php
  $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08');
  $data = array();
  foreach($array as $item){
    if(isset($data[$item]))
      $data[$item]++;
    else
      $data[$item] = 1;
  }
  print_r($data);
?>

Have you looked at the function array_count_values()?

<?php
  $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08');
  $data = array_count_values($array);
  echo '<pre>' . print_r($data,true) . '</pre>';
?>

 

Ken

Have you looked at the function array_count_values()?

<?php
  $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08');
  $data = array_count_values($array);
  echo '<pre>' . print_r($data,true) . '</pre>';
?>

 

Ken

 

always taking shortcuts.... ;)

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.