Search the Community
Showing results for tags 'php array'.
-
Few days back i made an associative array UDF for a project as autoit does not have associative array/PHP style array support.it does not keep up to the quality of the example scripts posted in this forum. I hope it may be useful to other amateur developers like me. Main UDF file: associative_arrays.au3 CHM help file: associativearray_chm.zip list of main functions: _SetAssociativeArray() _AddAssociativeArray() _AssociativeArray() print_r() array2json() Json2Array() example script: #include <associative_arrays.au3> $datas = '' ; creates a variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Associative_array exmples ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;first example: seting an array value $value = _SetAssociativeArray($datas, 'roger->royal->datar', '','changedatata=>>inprogressd', True) ConsoleWrite(@CR&'first example: seting an array value'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf $value = _AddAssociativeArray($datas, 'roger->royal->datar->0', -1, 'changedatata=>>inprogress', True) ;makes a sub array ConsoleWrite(@CR&'creating a non existent array path roger->royal->datar->0'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;second example: pushing an element to the end of an array $value = _AddAssociativeArray($datas, 'roger->royal->datar', -1, 'changedatata=>>inpro', True) ConsoleWrite(@CR&'second example: pushing an element to the end of an array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;third example: adding an element to the 2nd index position in the associative array $value = _AddAssociativeArray($datas, 'roger->royal->datar', 2, 'added element to 2nd position', True) ConsoleWrite(@CR&'third example: adding an element to the 2nd index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;fourth example: changing the element in the 2nd index position in the associative array $value = _SetAssociativeArray($datas, 'roger->royal->datar', 2, '2nd element changed') ConsoleWrite(@CR&'fourth example: changing the element in the 2nd index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;fifth example: changing the element in the first index position in the associative array $value = _SetAssociativeArray($datas, 'roger->royal->datar', 1, 'first element changed') ConsoleWrite(@CR&'fifth example: changing the element in the first index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf _SetAssociativeArray($datas, 'list', '', 'echo', True);makes another array in the root $value = _AssociativeArray($datas, 'roger->royal->datar') _ArrayDisplay($value, 'sixth example: reading an array at the position roger->royal->datar') ConsoleWrite(@CR & 'seventh example: reading the second element of an array'& @CR &_AssociativeArray($datas, 'roger->royal->datar', 2)) $value = _AssociativeArray($datas, 'roger->royal->data') _ArrayDisplay($value, 'eighth example: trying to read an array which doesnt exist') ;print_r($datas) $test_json = '{"0":"again0","1":"again1","5":{"0":"test1","male":["asf","s:dfs,f"," boo\r\n hoo"],"1":"test2","2":"test\t3","3":"dgdg \\n fdgd"},"6":"test4","7":"test5"}' $json_test_array = '' $value = Json2Array($json_test_array, $test_json) ConsoleWrite(@CR&'Converting a json to an associative array'&@CR) If $value > -1 Then print_r($json_test_array) Else ConsoleWrite("Failed: " & $value) EndIf ConsoleWrite(@crlf&'Converting an associative array to json'&@CR& array2json($json_test_array)&@CRLF) ConsoleWrite(Get_Ass_Array($json_test_array, '0', 0, True)&@CR) Do let me know if there are any bugs.. Thank you..