locked
help converting a php array to C# RRS feed

  • Question

  • User193749913 posted
     I'm needing help converting the php array in red below. I've been able to convert some of the arrays to dictionaries but not sure what the best solution
    iis since this is an array inside of an array .

    $reg_rows=array(); $rc_count=0; $reg_counter=0; $hold_achtrndt="1970-01-01"; $hold_regpay_sort="0"; while ( ($row_rc=sqlsrv_fetch_assoc($result_rc)) )
    { if ( strtoupper(substr($row_rc['tb_value1'],4,1))=="Y" )
    $reg_counter=count($reg_rows); //If the paymethod is set to require it's own deposit, increment elseif ( $row_rc['regpay_sort']!=$hold_regpay_sort )
    { $reg_counter=count($reg_rows); //If the paymethod changes, increment so each different type is separated $hold_regpay_sort=$row_rc['regpay_sort']; } $reg_rows[$reg_counter][$row_rc['rc_code']]=$row_rc; THIS IS THE ARRAY I NEED HELP WITH $rc_count++; }
    Maybe it would be easier if I showed you what I'm trying to get. Example below. where 0 and 1 would be the reg_counter and 5514,5115,5116 would be the $row_rc['rc_code'] and the array[78] are the fields returned from SQL table.
    $reg_rows[0][5515]{array[78]}
    $reg_rows[1][5514]{array[78]}
    $reg_rows[1][5516]{array[78]}

    Tuesday, March 12, 2019 7:09 PM

All replies

  • User36583972 posted

     I'm needing help converting the php array in red below. I've been able to convert some of the arrays to dictionaries but not sure what the best solution
    iis since this is an array inside of an array .    
    
    $reg_rows=array();
    	$rc_count=0;
    	$reg_counter=0;
    	$hold_achtrndt="1970-01-01";
    	$hold_regpay_sort="0";
    	while ( ($row_rc=sqlsrv_fetch_assoc($result_rc)) ) 
            {
    		if ( strtoupper(substr($row_rc['tb_value1'],4,1))=="Y" )
                           $reg_counter=count($reg_rows);  //If the paymethod is set to require it's own deposit, increment
    		elseif ( $row_rc['regpay_sort']!=$hold_regpay_sort ) 
                    {
    			$reg_counter=count($reg_rows);  //If the paymethod changes, increment so each different type is separated
    			$hold_regpay_sort=$row_rc['regpay_sort'];
    		}
    		$reg_rows[$reg_counter][$row_rc['rc_code']]=$row_rc; THIS IS THE ARRAY I NEED HELP WITH
    		$rc_count++;
    	}
    Maybe it would be easier if I showed you what I'm trying to get. Example below. where 0 and 1 would be the reg_counter and 5514,5115,5116 would be the $row_rc['rc_code'] and the array[78] are the fields returned from SQL table.
    $reg_rows[0][5515]{array[78]}
    $reg_rows[1][5514]{array[78]}
    $reg_rows[1][5516]{array[78]}
    
    


    Hi trev52,

    Unfortunately, we are not familiar with PHP, and I don't know of any tool that can convert from PHP to C#.

    So, I suggest you can consult with someone who are familiar with PHP and try to implement the same function with C#.

    Thank you for your understanding.


    Best Regards

    Yong Lu

    Wednesday, March 13, 2019 6:05 AM
  • User409696431 posted

    Since I don't code in PHP, all I can suggest is that you read the following pages:

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/multidimensional-arrays  (Multi-dimensional arrays)

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/jagged-arrays (Jagged Arrays)

    See if you can find examples in those pages that match what you are trying to create, or that provide a different option that would work for what you need.  The examples include how to populate and read from the various arrays.

    Wednesday, March 13, 2019 8:39 AM
  • User-1340885213 posted

     I'm needing help converting the php array in red below. I've been able to convert some of the arrays to dictionaries but not sure what the best solution
    iis since this is an array inside of an array .    
    
    $reg_rows=array();
    	$rc_count=0;
    	$reg_counter=0;
    	$hold_achtrndt="1970-01-01";
    	$hold_regpay_sort="0";
    	while ( ($row_rc=sqlsrv_fetch_assoc($result_rc)) ) 
            {
    		if ( strtoupper(substr($row_rc['tb_value1'],4,1))=="Y" )
                           $reg_counter=count($reg_rows);  //If the paymethod is set to require it's own deposit, increment
    		elseif ( $row_rc['regpay_sort']!=$hold_regpay_sort ) 
                    {
    			$reg_counter=count($reg_rows);  //If the paymethod changes, increment so each different type is separated
    			$hold_regpay_sort=$row_rc['regpay_sort'];
    		}
    		$reg_rows[$reg_counter][$row_rc['rc_code']]=$row_rc; THIS IS THE ARRAY I NEED HELP WITH
    		$rc_count++;
    	}
    Maybe it would be easier if I showed you what I'm trying to get. Example below. where 0 and 1 would be the reg_counter and 5514,5115,5116 would be the $row_rc['rc_code'] and the array[78] are the fields returned from SQL table.
    $reg_rows[0][5515]{array[78]}
    $reg_rows[1][5514]{array[78]}
    $reg_rows[1][5516]{array[78]}
    
    

    Not all PHP is strongly typed. However, you need to change it in your C# code as it is strongly typed. In your PHP code you have called the 3 dimensional array dynamically.

    That can be done in C# also. However, you need to declare it that way. The following line will give you an idea.

    int[, ,] reg_rows = new int[[0][5515]{array[78]}];

    Monday, December 23, 2019 1:28 AM