PHP sop2 functions-1
PHP sop2 functions-1
PHP Arrays
An array stores multiple values in one single variable. An array is a special variable, which can
hold more than one value at a time. An array can hold many values under a single name, and you
can access the values by referring to an index number. In PHP, the array() function is used to
create an array:
The array_splice() function removes selected elements from an array and replaces it with new
elements. The function also returns an array with the removed elements.
Syntax
array_splice(array, start, length, array)
Parameter Values
Description
start Required. Numeric value. Specifies where the function will start removing
elements. 0 = the first element. If this value is set to a negative number, the
function will start that far from the last element. -2 means start at the second last
element of the array.
length Optional. Numeric value. Specifies how many elements will be removed, and
also length of the returned array. If this value is set to a negative number, the
function will stop that far from the last element. If this value is not set, the
function will remove all elements, starting from the position set by the start-
parameter.
array Optional. Specifies an array with the elements that will be inserted to the
original array. If it's only one element, it can be a string, and does not have to be
an array.
The foreach loop works only on arrays, and is used to loop through each key/value pair in an
array. The foreach loop - Loops through a block of code for each element in an array.
Syntax
foreach ($array as $value) {
code to be executed;
}
For every loop iteration, the value of the current array element is assigned to $value and the array
pointer is moved by one, until it reaches the last array element.