csv 파일을 HTML 표로 변환하려고합니다. 첫 번째 부분에서는 CSV 파일의 모든 시간 셀을 시간 배열로, 이벤트 셀을 이벤트 배열로, 위치 셀을 위치 배열로로드하려고합니다.배열이 비어있는 이유는 무엇입니까?
fclose($file);
이후에 나는 print_r($time);
을 작성했으며 Array ([0] => Time)
을 반환했습니다. 그러나 get_data($time, $events, $location);
이후에, 나는 print_r($time);
을했고 Array()
을 얻었다. 왜 비어 있습니까? 모든 시간 셀을 시간 배열, 이벤트 셀을 이벤트 배열, 위치 셀을 위치 배열에로드하려면 어떻게해야합니까?
EventsScheduleFriday.csv
Time,Event,Location,
12:30pm,Hilby The Skinny German Juggle Boy,West State Street,
4:45pm,Hilby The Skinny German Juggle Boy,West State Street,
6pm,Finger Lakes Comedy Festival Competition 1st Round (Age 21+),Lot 10,
8pm,Stand-up Comedy Show,Acting Out NY,
10pm,All-Star Comedy Show,Acting Out NY
PHP 코드 : 이것은 당신이 방법의 범위를 벗어난다 변수를 사용하기 때문에 경우에 발생
<?php
$time = array();
$events = array();
$location = array();
function get_data($time, $events, $location) {
$file = fopen(__DIR__."/../data/EventsScheduleFriday.csv", "r"); //read .csv file
while(!feof($file)) { //while end of file has not been reached
$content = fgetcsv($file, ","); //converts first line of csv to an array
array_push($time, $content[0]);
array_push($events, $content[1]);
array_push($location, $content[2]);
}
fclose($file); //closes csv file
}
get_data($time, $events, $location);
?>