Help to Understand PHP Code into C#
        Posted  
        
            by user342944
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user342944
        
        
        
        Published on 2010-05-17T10:57:21Z
        Indexed on 
            2010/05/17
            11:00 UTC
        
        
        Read the original article
        Hit count: 174
        
Hi Gurus,
I am a C# guy and got this logic into php from a website. Need to implement the same in C#.
$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";
}
In the above last line is it a 3 dimensional array or hashtable? it looks like its a hashtable cause [$pkey]['children'][$ckey] is bugging me..
Can anyone convert the above code in C#? I would really appreciate.
© Stack Overflow or respective owner