-3

好的,所以我有以下代码(在数组上完全按照我想要的方式工作)它在一个名为 courseInfo() 的数组上工作并更改它。

$sizev1 = sizeof($courseInfo);
for ($row = 0; $row < $sizev1; $row++)
{
$tempsemhrs= $courseInfo[$row][3];
$tempday= $courseInfo[$row][4];
    if ($tempday == "א") $tempday=1;
    if ($tempday == "ב") $tempday=2;
    if ($tempday == "ג") $tempday=3;
    if ($tempday == "ד") $tempday=4;
    if ($tempday == "ה") $tempday=5;
    if ($tempday == "ו") $tempday=6;
$tempstarttime= $courseInfo[$row][5];
    if( (StrDelete($tempstarttime, 2, 3)-7) <10 )
        if( (StrDelete($tempstarttime, 0, 3)) == "45" )
            $tempstarttime= "0".(StrDelete($tempstarttime, 2, 3)-7+1);
        else
            $tempstarttime= "0".(StrDelete($tempstarttime, 2, 3)-7);
    if( (StrDelete($tempstarttime, 2, 3)-7) >=10 )
        if( (StrDelete($tempstarttime, 0, 3)) == "45" )
            $tempstarttime= (StrDelete($tempstarttime, 2, 3)-7+1);
        else
            $tempstarttime= (StrDelete($tempstarttime, 2, 3)-7);        


$courseInfo[$row][6]= ( $courseInfo[$row][2].$tempsemhrs.$tempday.$tempstarttime);

}

现在,还有几个地方我可能不得不使用该代码,所以我考虑将它变成一个函数而不是加倍代码,但是当我尝试它不再工作时,我所做的只是将它复制到函数 {} 并更改里面的名字,它不起作用,我也把它复制在这里,我很想有人告诉我哪里出错了,为什么现在不起作用?

function addSortingCode ($tableChange)
{
$sizev1 = sizeof($tableChange);
for ($row = 0; $row < $sizev1; $row++)
    $tempsemhrs= $tableChange[$row][3];
    $tempday= $tableChange[$row][4];
        if ($tempday == "א") $tempday=1;
        if ($tempday == "ב") $tempday=2;
        if ($tempday == "ג") $tempday=3;
        if ($tempday == "ד") $tempday=4;
        if ($tempday == "ה") $tempday=5;
        if ($tempday == "ו") $tempday=6;
    $tempstarttime= $tableChange[$row][5];
        if( (StrDelete($tempstarttime, 2, 3)-7) <10 )
            if( (StrDelete($tempstarttime, 0, 3)) == "45" )
                $tempstarttime= "0".(StrDelete($tempstarttime, 2, 3)-7+1);
            else
                $tempstarttime= "0".(StrDelete($tempstarttime, 2, 3)-7);
        if( (StrDelete($tempstarttime, 2, 3)-7) >=10 )
            if( (StrDelete($tempstarttime, 0, 3)) == "45" )
                $tempstarttime= (StrDelete($tempstarttime, 2, 3)-7+1);
            else
                $tempstarttime= (StrDelete($tempstarttime, 2, 3)-7);        


    $tableChange[$row][6]= ( $tableChange[$row][2].$tempsemhrs.$tempday.$tempstarttime);
    }
 }
addSortingCode ($courseInfo);
4

2 回答 2

2

你可以这样做:

//return the final contructed array(here $tableChange) as function output
function addSortingCode($tableChange)
{

     //your code
     return $tableChange;
}

//calling of the function

 $output = addSortingCode($courseInfo);
于 2013-07-14T08:20:07.647 回答
0

$tableChange变量不会在函数内部被修改。尝试通过引用传递,而不是将您的函数签名更改为

function addSortingCode (&$tableChange)
于 2013-07-14T08:16:33.747 回答