Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP代码转换为Vb.net_Php_Vb.net - Fatal编程技术网

将PHP代码转换为Vb.net

将PHP代码转换为Vb.net,php,vb.net,Php,Vb.net,我在vb.net中遇到了一个问题,关于如何将数据放入多维数组中,循环遍历它,并将结果打印为字符串 现在我用php解决它,但我不能在vb.net中解决它。我不熟悉vb.net,也不熟悉多维数组 这是我的PHP脚本 $first_dimensionarray = array();//empty array $second_dimensionarray = array();//empty array for($i = 0; $i < count (

我在vb.net中遇到了一个问题,关于如何将数据放入多维数组中,循环遍历它,并将结果打印为字符串

现在我用php解决它,但我不能在vb.net中解决它。我不熟悉vb.net,也不熟悉多维数组

这是我的PHP脚本

$first_dimensionarray = array();//empty array
            $second_dimensionarray = array();//empty array
            for($i = 0; $i < count ( $data); $i ++){
            //loop through the data
            $second_dimensionarray = array(strtotime($data['date']),  $data['name']  , $data['phone'] , $data['email'] ,$data['date']  );//put every record as array in second_dimensionarray
            array_push( $first_dimensionarray, $second_dimensionarray ); //push second_dimensionarray inside the first_dimensionarray 
            }
            sort( $first_dimensionarray ); //sort $first_dimensionarray by the first element   >> (strtotime($data['date'])
            $arraycheck = array(); //another array to put the names into it
            for($i = 0; $i < count ( $first_dimensionarray ); $i ++)// loop through the new dimensional array --first_dimensionarray
            { 
                if(!in_array($first_dimensionarray[$i][1],$arraycheck ))//check if name exsit in arraycheck 
                {     
                        $arraycheck[] =$first_dimensionarray[$i][1];// if not then add it to arraycheck 
                        unset($first_dimensionarray[$i][0]);//remove the first index (the purpose for this element (date) is to sort all Data by  date)
                        $string .= implode( ",", $first_dimensionarray[$i] );
                        $string .= "\n";

                }
            }
   For i = 0 To ata.Count 
              second_dimensionarray(i) = (strtotime($data('date')),$data('name'),$data('phone'),$data('email'),$data('date')}
              Array.Copy(second_dimensionarray, first_dimensionarray, 13)
              Next i

有谁能帮我在vb.net中重写这段php代码吗?

我不确定您的数据是由什么提供的,所以我只是以DataTable为例。首先,创建一个类(或结构)。VB编译器将为每个属性创建getter、setter和backer字段。当然,如果需要getter或setter中的代码,可以将其拼出来。还将创建一个默认构造函数。 如果使用常规列表而不是数组,则无需定义大小。循环遍历数据,首先创建类的新实例,然后为属性赋值。然后将实例添加到列表中。一旦有了列表,您就可以轻松地对属性进行排序和访问

Public Class Form1
Private Sub ConvertPHP()
        Dim strData As DataTable
    Dim lstPerson As New List(Of Person)
    For i As Integer = 0 To strData.Rows.Count - 1
        Dim p As New Person()
        p.Time = CDate(strData.Rows(i)("date")).ToShortTimeString
        p.Name = strData.Rows(i)("name").ToString
        p.Phone = strData.Rows(i)("phone").ToString
        p.Email = strData.Rows(i)("email").ToString
        p.PDate = CDate(strData.Rows(i)("date"))
        p.Children = {"Mathew", "Mark", "Luke", "John"}
        lstPerson.Add(p)
    Next
    Debug.Print(lstPerson.Item(0).Children(0))
    Dim lstSortedByName As List(Of Person) = lstPerson.OrderBy(Function(p) p.Name).ToList
    For i As Integer = 0 To lstPerson.Count - 1
        If String.IsNullOrWhiteSpace(lstPerson.Item(0).Name) Then
            'Do something
        End If
    Next
End Sub
End Class
Class Person
    Public Property Time As String
    Public Property Name As String
    Public Property Phone As String
    Public Property Email As String
    Public Property PDate As DateTime
    Public Property Children As String()
End Class

感谢您的回复,但我有一个问题,我如何才能在这行lstPerson.add(p)中添加元素数组。。。对于索引=0到4个Dim学生(4)就像字符串学生(0)=“asd”学生(1)=asd@ytg.xcom“学生(2)=“1313123”学生(3)=“2/2/1210”学生(4)=“12345”等加上(学生)NextI向类和示例中添加了一个数组属性。嗯