好的,所以我有下面的代碼(工作完全按照我想要在一個數組上) 它在一個名爲courseInfo()的數組上工作並對其進行更改。將代碼變成函數php
$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);
}
現在,還有另一個幾個地方我可能會使用這些代碼,所以我想過使它成爲加倍代碼的功能istead,但是當我試圖它沒有工作了,所有的我所做的是將其複製到函數{}中,並更改名稱內部,它不起作用,即時複製它在這裏也,我很想有人告訴我我哪裏出錯了,爲什麼現在不工作?
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);
http://php.net/functions - 題目是更爲寬廣,所以它的通常建議閱讀使用手冊並在使用前理解概念。你不是那麼遠,但考慮到你的函數與代碼的其餘部分是分開的,所以它們的變量也是如此。重要的是:http://php.net/variables.scope – hakre