2012-03-27 5 views
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]" 

すべての援助を歓迎します。私はので、私は、配列年代にXMLファイルを解析してい +:それはいつも同じパターンを持っているので、私は、コードの次のブロックからの再帰関数を作ってるんだ :


このすべてのFOT理由私は、これはあなたが何を意味するかですが、あなたがあなたの最後の「スーパーアレイ」を追跡し、それに項目を追加したい場合は、追跡することにより、そうすることができるかどうかわからないのですdrupalの

$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++; 
} 
} 
+0

はa.b.c.dの鍵ですints?このデータセットの効率的な形状があるように見えます。 –

+0

こういうことをする可能性はありますか?まあ、あなたはそのようなことをしましたか? – FlavorScape

+2

はい、可能ですが、なぜそのようなものが必要ですか? – safarov

答えて

0

で、後でそれを使用することができます(&)を最後のスーパーアレイに割り当てます。

$input = array($b, $c, $d, $e); 
$result = array('chapters' => array($a => array())); 
$current = &$result['chapters'][$a]; 

foreach ($input as $iter) { 
    $current['subject'][$iter] = array("title" => (string) $iter); 
    $current = &$current['subject'][$iter]; 
} 
関連する問題