0
동적 다차원 배열을 만들 수 있습니까?동적 다차원 배열을 만들 수 있습니까?
배열을 사용하여 재귀 함수를 만들고 싶습니다. 내가 말할 수있는 경우 은 그래서 멋진 것 뭔가
$array['chapters'][$a]['subject'][$b] = array("title" => (string) $item);
다음 번에 같은 -는,이
$array['chapters'][$a]['subject'][$b]['subject'][$c] = array("title" => (string) $item);
과 같은
$array['chapters'][$a]['subject'][$b]['subject'][$c]['subject'][$d] = array("title" => (string) $item);
하고, 될
$array['chapters'][$a]['subject'][$b]['subject'][$c]['subject'][$d]['subject'][$e] = array("title" => (string) $item);
및
그래서, 이와 같은 일을 할 가능성이 있습니까?
$superArray = "$array['chapters'][$a]['subject'][$b]"
과 다음번
,superArray += "['subject'][$c]"
??
모든 도움을 환영합니다.
이 모든 FOT 이유 : 항상 같은 패턴이 있기 때문에 나는 코드의 다음 블록에서 재귀 함수를 만들고있어 : 가 + 내가 있도록 배열의로 XML 파일을 구문 분석하고 있습니다를 내가 이것은 당신이 무엇을 의미하는지 경우
$resulty = $xpaths->xpath("/org.olat.course.Structure/rootNode/children/*[ident = '$item->ident']/children/*[type = 'st' or type = 'sp' or type = 'bc']");
if ($resulty > 0) {
foreach ($resulty as $itemy) {
$x = 0;
$array['chapters'][$s]['subject'][$d] = array(
'id' => (string) $itemy->ident,
'shortTitle' => (string) $itemy->shortTitle,
'type' => (string) $itemy->type,
);
switch ($itemy->type) {
case "bc":
$course_map = getDirectoryList("/opt/olat/olatdata/bcroot/course/$course/foldernodes/$item->ident");
for ($i = 0; count($course_map) > $i; $i++) {
$location = "/opt/olat/olatdata/bcroot/course/$course/foldernodes/$item->ident/$course_map[$i]";
$array['chapters'][$s]['subject'][$d]['files'][$x] = array(
"name" => $course_map[$i],
"location" => $location,
"size" => format_bytes(filesize($location)),
"type" => filetype($location),
"modified" => date("F d Y H:i:s.", filemtime($location))
);
}
break;
case "sp" || "st" :
$resultz = $xpaths->xpath("//*[ident = '$itemy->ident']/moduleConfiguration/config//string[starts-with(.,'/')]");
foreach ($resultz as $itemz) {
$array['chapters'][$s]['subject'][$d] += array(
"html-page" => (string) $itemz,
);
}
break;
}
<<<--- When you go deeper, than all this wil be set here
$d++;
$x++;
}
}
은 a.b.c.d key ints입니까? 이 데이터 세트에 대해보다 효율적인 모양이있는 것처럼 보입니다. –
이렇게, 이런 일을 할 가능성이 있습니까? 글쎄, 니가 그런 짓을 한거야? – FlavorScape
예, 가능하지만 왜 그런 것이 필요한가요? – safarov