View Single Post

  #4 (permalink)  
Old 10-12-2004
Aldo
 
Posts: n/a
Default Re: rewrite asp code to php

Yes i think you're right ;-)…

here the two functions I can't get to work in php.
the array who is feeding the function "GenerateNestedArray" has this structure:
$mArrContent[1][0]=0; 'counter
$mArrContent[1][1]=42; 'id
$mArrContent[1][2]="folder"; 'folder or page
$mArrContent[1][3]="Leistungen"; 'title
$mArrContent[1][4]=34; 'parent id

my goal is to build a multidimensional array with the right folder structure


ASP
-------------
'Call the function to Generate the Nested Array
marrMain = GenerateNestedArray(mArrContent)

'/**********************************
'This is the function that generate
'the nested array based on a given
'multidimensional array
'/**********************************
Function GenerateNestedArray(ArrContent)
Dim arrMain
Dim arrSub
Dim arrSubContent
Redim arrSub(5)
Redim arrMain(0)
Dim lngCount
For i = 1 to UBound(arrContent)
Redim arrSubContent(0)
if arrContent(i,4) = 34 then
lngCount = lngCount + 1
Redim Preserve arrMain(lngCount)
For j = 0 to 4
arrSub(j) = ArrContent(i,j)
next
arrSub(5) = arrSubContent
arrMain(lngCount) = arrSub
else
for j = 1 to Ubound(arrMain)
For k = 0 to 4
arrSub(k) = arrContent(i,k)
next
arrSub(5) = arrSubContent
if FindParent(arrMain(j), arrSub) = true then
exit for
End if
Next
end if
next
GenerateNestedArray = arrMain
end function

'/**********************************
'This is the function that
'recursively find the parent
'folder of a given page or folder
'and then places the data into
'the fifth element of the parent array
'/**********************************
Function FindParent(arrParent, arrContent)
On error resume next
Dim arrSub(5)
Dim arrTemp(5)
Dim arrSubContent(0)
Dim arrSubArray
Dim lngCount
if arrParent(1) = arrContent(4) then
For j = 0 to 4
arrSub(j) = arrContent(j)
next
arrSub(5) = arrSubContent
if Ubound(arrParent(5)) = 0 then
lngCount = 1
redim ArrSubArray(1)
arrSubArray(1) = arrSub
else
lngCount = Ubound(arrParent(5)) + 1
Redim arrSubArray(lngCount)
for j = 1 to lngCount -1
arrSubArray(j)= arrParent(5)(j)
Next
arrSubArray(lngCount) = arrContent
end if
arrParent(5) = arrSubArray
FindParent = true
Exit Function
elseif Ubound(arrParent(5)) > 0 then
for i = 1 to Ubound(arrParent(5))
blnFindParent = FindParent(arrParent(5)(i), arrContent)
if blnFindParent = true then
Exit function
end if
next
end if
FindParent = false
End Function

PHP
--------------------

//Call the function to Generate the Nested Array
$marrMain=GenerateNestedArray($mArrContent);

//Call the function to Generate the HTML script
GenerateHTML($marrMain);





///**********************************
// This is the function that generate
// the nested array based on a given
// multidimensional array
///**********************************


function GenerateNestedArray($arrContent) {

$arrMain = array();
$arrSub = array();
$arrSubContent = array();

for ($i=1;$i<=count($arrContent);$i++) {

if ($arrContent[$i][4]==34) {
$lngCount++;
for ($j=0;$j<=4;$j++) {
$arrSub[$j] = $arrContent[$i][$j];
}
$arrSub[5] = $arrSubContent;
$arrMain[$lngCount] = $arrSub;

} else {

for ($j=1;$j<=count($arrMain);$j++) {

for($k=0;$k<4;$k++){
$arrSub[$k] = $arrContent[$i][$k];
}
$arrSub[5] = $arrSubContent;
if (FindParent($arrMain[$j],$arrSub)===false) {
break;
}
}

}
}

return $arrMain;
}

///**********************************
// This is the function that
// recursively find the parent
// folder of a given page or folder
// and then places the data into
// the fifth element of the parent array
///**********************************


function FindParent($arrParent,$arrContent) {

$arrSub = array();
$arrSubContent = array();
$arrSubArray = array();

if ($arrParent[1]==$arrContent[4]) {

for ($j=0;$j<=4;$j++) {
$arrSub[$j] = $arrContent[$j];
}
$arrSub[5] = $arrSubContent;

if(count($arrParent[5])==0) {
$lngCount = 1;
$arrSubArray[] = $arrSub;
} else {
$lngCount = count($arrParent[5])+1;
for($j=1;$i<=$lngCount-1;$j++) {
$arrSubArray[$j] = $arrParent[5][$j];
}
$arrSubArray[$j] = $arrContent;
}

$arrParent[5] = $arrSubArray;
return true;

} else if (count($arrParent[5])>0) {

for ($i=1;$i<=count($arrParent[5]);$i++) {
$blnFindParent = FindParent($arrParent[5][$i],$arrContent);
if ($blnFindParent == true) {
break;
}
}
}

return false;

}

"Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> wrote in message news:<lgh250l3cvcz.1dj1915u8asuj.dlg@40tude.net>.. .
> *** Aldo escribió/wrote (11 Oct 2004 10:16:16 -0700):
> > i'm trying to translate this asp code to php, but i can't get it work right.
> > could anyone help me?

>
> Maybe if you could shorten the question... Nobody's going to check six
> hundred lines of code for you.

Reply With Quote