Maximales "ArrayDisplay" (ähnlich wie Print_r aus PHP)

  • Heyho Autoit.de!

    Vor einiger Zeit gab es in unserem Forum (die "Dunkle Seite" wie sie Peethebee nennen würde :rolleyes: ) eine Anfrage auf eine UDF, die es einem ermöglichen sollte eine unbestimmte anzahl von arraydimensionen darzustellen, da sich _ArrayDisplay nur auf 2 Dimensionen beschränkt.

    Ich habe mich also mal eine weile rangesetzt und es ist etwas sinvolles bei rausgekommen :P
    Da ich mit eurer sufu keine ähnliche udf gefunden habe, dachte ich mir, dass ihr vielleicht auch interresse an so einer UDF hättet und habe deshalb dieses Thread erstellt 8)

    Hier also die UDF mit Beispiel:

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.0.0
    Author: Deathly Assassin

    [/autoit] [autoit][/autoit] [autoit]

    Script Function:
    Displays an unlimmited amount of array dimensions in a dialog box

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $0Dim = '0'
    MsgBox(0, "", print_r($0Dim))

    [/autoit] [autoit][/autoit] [autoit]

    Dim $1Dim[5]
    $1Dim[0] = '0'
    $1Dim[1] = '1'
    $1Dim[2] = '2'
    $1Dim[3] = '3'
    $1Dim[4] = '4'
    MsgBox(0, "", print_r($1Dim))

    [/autoit] [autoit][/autoit] [autoit]

    Dim $2Dim[5][2]
    $2Dim[0][0] = '0x0'
    $2Dim[0][1] = '0x1'
    $2Dim[1][0] = '1x0'
    $2Dim[1][1] = '1x1'
    $2Dim[2][0] = '2x0'
    $2Dim[2][1] = '2x1'
    $2Dim[3][0] = '3x0'
    $2Dim[3][1] = '3x1'
    $2Dim[4][0] = '4x0'
    $2Dim[4][1] = '4x1'
    MsgBox(0, "", print_r($2Dim))

    [/autoit] [autoit][/autoit] [autoit]

    Dim $3Dim[2][2][2]
    $3Dim[0][0][0] = '1'
    $3Dim[0][0][1] = '2'
    $3Dim[0][1][0] = '5'
    $3Dim[0][1][1] = '6'
    $3Dim[1][0][0] = '7'
    $3Dim[1][0][1] = '8'
    $3Dim[1][1][0] = '9'
    $3Dim[1][1][1] = '10'
    MsgBox(0, "", print_r($3Dim))

    [/autoit] [autoit][/autoit] [autoit]

    Func print_r($aArray)
    Local $i, $s = 'Array{' & @CRLF, $sFor_execute = '', $sFor_execute_temp, $count=1
    If IsArray($aArray) Then
    $cDimensionen = UBound($aArray, 0)
    For $i = 1 To $cDimensionen
    Assign('$c' & $i, 0, 2)
    Assign('$c' & $i &'_Max', UBound($aArray, $i) - 1, 2)
    $count*=UBound($aArray, $i)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    For $o=$count To 1 Step -1
    For $i = 1 To $cDimensionen
    $s &= '['&Eval('$c' & $i) & ']'
    Next
    $s &= ' => '
    For $i = 1 To $cDimensionen
    $sFor_execute_temp &= '['&Eval('$c'&$i) & ']'
    Next
    $s &= Execute('$aArray'&$sFor_execute_temp)
    $s &= @CRLF
    $sFor_execute_temp=""
    _Assign_For_Schleifen($cDimensionen)
    Next
    Else
    Return $aArray
    EndIf
    Return $s & '}' & @CRLF
    EndFunc ;==>print_r

    [/autoit] [autoit][/autoit] [autoit]

    Func _Assign_For_Schleifen($cDimensionen)
    Local $o
    For $o=$cDimensionen To 1 Step -1
    If Eval('$c' & $o)=Eval('$c' & $o &'_Max') Then
    Assign('$c' & $o, 0)
    _Assign_For_Schleifen($cDimensionen-1)
    ExitLoop
    Else
    Assign('$c' & $o, Eval('$c' & $o)+1)
    ExitLoop
    EndIf
    Next
    EndFunc

    [/autoit]