Retrieving an Element of an Array: Difference between revisions
Content added Content deleted
(Added PHP example) |
Thundergnat (talk | contribs) (blanked page since people can't / don't read) |
||
(155 intermediate revisions by 52 users not shown) | |||
Line 1: | Line 1: | ||
{{ |
{{DeprecatedTask}} |
||
'''Please do not add new code, and merge existing code to the [[Arrays]] task.''' |
|||
In this task, the goal is to retrieve an element of an [[array]]. |
In this task, the goal is to retrieve an element of an [[array]]. |
||
==[[mIRC]]== |
|||
'''Interpeter:''' mIRC Script Editor |
|||
'''Library:''' [[mArray Snippet]] |
|||
alias readmyarray { echo -a $array_read(MyArray, 2, 3) } |
|||
==[[C]]== |
|||
int array_index(int array[], int index) { |
|||
return array[index]; |
|||
} |
|||
==[[C plus plus|C++]]== |
|||
template <class T> |
|||
T array_index(T *array, int index) { |
|||
return array[index]; |
|||
} |
|||
==[[C sharp|C#]]== |
|||
int getArrayValue( int values[], int index ) { |
|||
return values[index]; |
|||
} |
|||
==[[Common Lisp]]== |
|||
(defun array-value (array index) |
|||
(aref array index)) |
|||
==[[Perl]]== |
|||
'''Interpreter:''' [[Perl]] 5.8.8 |
|||
$elem = $array[0]; |
|||
==[[PHP]]== |
|||
$array = array('php', 'has', 'arrays'); |
|||
// First element |
|||
$elem = $array[0]; |
|||
==[[Ruby]]== |
|||
ary = ['Ruby','rules','big','time'] |
|||
#the first element |
|||
element = ary[0] |
|||
#or |
|||
element = ary.first |
|||
# => element = 'Ruby' |
|||
#the last element |
|||
element = ary[-1] |
|||
#or |
|||
element = ary.last |
|||
# => element = 'time' |
|||
#retrieving different values at once |
|||
elements = ary.values_at(0,2,3) |
|||
# => elements = ['Ruby','big','time'] |
|||
#select the first element of length 3 |
|||
element = ary.find{|el|el.length==3} |
|||
# => element = "big" |
|||
==x86 assembly== |
|||
'''Assembler:''' nasm |
|||
mov esi, array_offset |
|||
mov ebx, 2 |
|||
mov eax, [esi+ebx*4] |
|||
{{array operation}} |
Latest revision as of 15:06, 29 November 2019
Retrieving an Element of an Array was a programming task. It has been deprecated for reasons that are discussed in its talk page.
Please do not add new code, and merge existing code to the Arrays task.
In this task, the goal is to retrieve an element of an array.