====== Array ======
Arrays are the most basic type of [[List|list]] available in most programming languages. Arrays occupy a contiguous area of storage and can be traversed randomly. Arrays are created to hold a certain number of elements and they can be accessed by supplying the index of the element in the array. [[For|loops]] are particularly useful for accessing arrays.
===== PHP =====
/* define array using auto-generated keys */
$data = array('apple', 'orange');
/* show values */ print_r($data); - Array - ( - [[0]] => apple - [[1]] => orange - )
/* define array with user-defined keys */ $data = array('a'=>'apple', 'o'=>'orange');
/* show values */
print_r($data);
- Array
- (
- [[a]] => apple
- [[o]] => orange
- )
<\/code>
**
===== Java =====
// define a class named array
class array {
// define main method of this java code
public static void main(String[[]] args){
// declare an array named intArray for integer type values
int[[]] intArray = {14,15,16,17,18};
for (int i = 0; i < intArray.length; i++) {
System.out.println((i+1) + " Element of array : " + intArray[[i]]);
}
}
} <\/code>
===== C++ =====
- include
// declate an empty array of string with a size variable size using STL.
std::vector<std::string> sVectorArray;
// if the cHeapArray is not needed anymore, free it by calling delete[[]] (not delete)!!!
delete[[]] cHeapArray;
return( EXIT_SUCCESS );
}
<\/code>