Ben bir C # adam ve bir web sitesinden php içine bu mantık var. C # aynı uygulamak gerekir.
$items = array();
while($row = mysql_fetch_assoc($query))
{
//parent id
$pkey = $row['parent_id'];
//child id
$ckey = $row['category_id'];
//store this
$items[$pkey]['children'][$ckey] = $row['categoryname'];
}
//create our list
$first = true;
//create our list
createList($items, $first);
function createList($array, $first)
{
//we need access to the original array
global $items;
//first is a flag on whether or not this is the first item in the array
//we use this flag so that you don't need to initially call the function using createList($array[0]['children'])
if($first){
$array = $array[0]['children'];
}
echo "<ol>\n";
foreach($array as $key => $value){
echo "<li>{$value}";
//if this item does have children, display them
if(isset($items[$key]['children'])){
echo "\n";
createList($items[$key]['children'], false); //set $first to false!
}
echo "</li>\n";
}
echo "</ol>\n";
}
Yukarıdaki son satırda bir 3 boyutlu dizi ya hashtable nedir? o [$ ckey] beni adamcağız onun bir hashtable nedenidir [$ pkey] ['çocuk'] gibi görünüyor ..
Herkes C # yukarıdaki kodu dönüştürebilir miyim? Ben gerçekten takdir ediyorum.