如何将数组作为参数传递给函数[关闭]

I made this code where I define an array, fliepath, in which I store the locations of some files.

     include 'last_file.php'; // Include the function last_file
     $last_file = last_file();  // assign to the function a variable and call the  function last_file
    // Connect to the database
     include('connect_thesis.php');

    // Defining an array, which has the three paths to the three different gps receivers
    $file_path[0] = "/Applications/MAMP/htdocs/php_test/check/".$last_file[0];
    //echo $file_path[0]; echo "<br>";
    $file_path[1] = "/Applications/MAMP/htdocs/php_test/check2/".$last_file[1];
    //echo $file_path[1]; echo "<br>";
    $file_path[2] = "/Applications/MAMP/htdocs/php_test/check3/".$last_file[2];
    //echo $file_path[2]; echo "<br>";

Then I made a function called insert() which I want to take as input the $file_path[0]:

     function insert($file_path){

     $fh = fopen($file_path,'r') or die ("Could not open:".mysql_error()).......;

I call the function from the main script as:

         insert($file_path[0]);

I am new in programming and I am sure somewhere I am missing something basic! The problem is that the function doesn't run!!! Can you help me? Thanx D.

I THINK I DONT PASS CORRECTLY THE VALUE TO THE FUNCTION. CAUSE I GET NOTHING AS AN ERROR!

A few points to note:

You are calling insert using only the index 0, consider using a foreach and call the function on each items in your array.

insert() -> we are missing part of the implementation, but if the file exists, you should not get an error. Keep in mind that you need to close files that you open.

or die -> it looks like you copy pasted code from elsewhere... mysql_error() will not help you much as you're dealing with files at the moment. Consider changing it to

$fh = fopen($file_path,'r') or die ("Could not open:".$file_path)

You should probably handle graciously the error instead of using "die"

I think you need this:

function insert($file_path) {
    foreach ($file_path as $file) {
        //Your code here
    }
}