Page 150 - Open Soource Technologies 304.indd
P. 150
Web Technologies-I
Notes Self Assessment
True or False:
5. The count( ) and sizeof( ) functions are identical in use and effect.
(a) True (b) False
6. array_pad( ) function is use to padding of array.
(a) True (b) False
7. The split command use to split an away.
(a) True (b) False
6.6 Summary
• An array in PHP is actually an ordered map. A map is a type that associates values to keys.
This type is optimized for several different uses; it can be treated as an array, list (vector),
hash table (an implementation of a map), dictionary, collection, stack, queue, and probably
more.
• There are two kinds of arrays in PHP: indexed and associative. The keys of an indexed
array are integers, beginning at 0. Indexed arrays are used when you identify things by
their position. Associative arrays have strings as keys and behave more like two-column
tables. The first column is the key, which is used to access the value.
• PHP internally stores all arrays as associative arrays, so the only difference between
associative and indexed arrays is what the keys happen to be.
• To access the contents of a variable, use its name. If the variable is an array, access the
contents using the variable name and a key or index. The key or index indicates which
stored values we access. The index is placed in square brackets after the name.
• Storing a value in an array will create the array if it didn’t already exist, but trying to
retrieve a value from an array that hasn’t been defined yet won’t create the array.
• To create an array initialized to the same value, use array_pad( ). The first argument to
array_pad( ) is the array, the second argument is the minimum number of elements you
want the array to have, and the third argument is the value to give any elements that are
created.
• Using an built-in function array_merge() we can merge two or more arrays to form a
single array. The values from the second array are appended at the end of first array and
so on.
• Searching for a value in an array is made simple using the function array_search(). If the
keyword is found in the array, then the corresponding key of that value is retured for
further operations.
6.7 Keywords
Associative arrays: Associative arrays have strings as keys and behave more like two-column
tables. The first column is the key, which is used to access the value.
Indexed arrays: Indexed array are integers, beginning at 0. Indexed arrays are used when you
identify things by their position.
144 LOVELY PROFESSIONAL UNIVERSITY