Jump to content

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.... ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.