-1

I am trying to create an array holding the dates of each title. However the $dates array is var_dumping int(1) rather than an array. And $dates[0] is NULL.

The csv files follow this formatting: log_2013_14_04.csv. The substr is working fine and cropping the date from the file, but why is the information not being added into the array?

$files = glob('*.csv');
$dates = array();
for($i=0;$i<count($files);$i++){
    $str = substr($files[$i],-14, -4);
    $dates = array_push($dates, $str);
}
var_dump($dates);

Thanks in advance!

Willow
  • 1,040
  • 2
  • 10
  • 21

2 Answers2

2

Because array_push returns new length of array not an array himself.

Denis Ermolin
  • 5,530
  • 6
  • 27
  • 44
  • Great, thanks! I misunderstood array_push then. I'm used to actionscript. How do I add a variable to the end of an array? I tried `$dates = $str;` but then $dates is a string. – Willow May 25 '13 at 08:00
2

It's either

array_push($dates, $str);

or

$dates[] = $str;

Not

$dates = array_push($dates, $str);
deceze
  • 510,633
  • 85
  • 743
  • 889