locked
converting an associative array to C# RRS feed

  • Question

  • User193749913 posted

    I'm in the process of converting some PHP code to C# and ran into an issue with an associative array. I've been converting them all to dictionaries but haven't had any luck with this code. I know this is a C# forum so don't know if anyone will be able to help converting PHP code but thought I would try.

    $menu_items=array();
         foreach ( $load_items as $k=>$v ) 
         {		
    	if ( ($row_item=include_menu_item($v['key'],$force_sc_code)) ) 
            {		
    		$menu_items[$v['key']]['title']=proper($row_item['sp_main_menu_text']);			
    		$menu_items[$v['key']]['caption']=strtolower($row_item['sp_caption']);
    		$menu_items[$v['key']]['url']="/"._BST_UseWWWFolder."/?p=".strtolower($row_item['sp_key']).(strlen($v['qstring'])?("&".$v['qstring']):"");
    	}
          }
          return $menu_items;

    Friday, May 19, 2017 5:59 PM

All replies

  • User-359936451 posted

    Probably not the answer your looking for. I have had a bit of success just dumping to an XML then importing with C#.

    Friday, May 19, 2017 8:24 PM
  • User303363814 posted

    Still not the answer you are looking for but ...

    Doing a straight conversion from one language to another is a very, very bad thing to do.  Not only do you get the bugs from the original code, you introduce new bugs by incorrect translations, your code will be harder to understand because it will attempt to follow (translated) idioms from the other language.  Ever heard of Chinese Whispers?

    Try to understand what the code does from a business perspective or a black box perspective, not an IT/code perspective.  What is the "big picture" of the problem that this code is trying to solve?  When you have worked out what the purpose of the code is then you know what the code is required to do.  Now, write a program which implements that requirement.

    It sounds like more work but in the long run it is actually much quicker and gives a better result which stands a chance of delivering what is actually required.

    Monday, May 22, 2017 4:58 AM