Welcome to Knowledge Base!

KB at your finger tips

This is one stop global knowledge base where you can learn about all the products, solutions and support features.

Categories
All
Web-PHP
PHP / APCUIterator::key — DevDocs

APCUIterator::key

(PECL apcu >= 5.0.0)

APCUIterator::key Get iterator key

Description

public APCUIterator::key(): string

Gets the current iterator key.

Parameters

This function has no parameters.

Return Values

Returns the key on success, or false upon failure.

See Also

  • APCUIterator::current() - Get current item
  • Iterator::key() - Return the key of the current element
PHP / APCUIterator::next — DevDocs

APCUIterator::next

(PECL apcu >= 5.0.0)

APCUIterator::next Move pointer to next item

Description

public APCUIterator::next(): bool

Moves the iterator pointer to the next element.

Parameters

This function has no parameters.

Return Values

Returns true on success or false on failure.

See Also

  • APCUIterator::current() - Get current item
  • APCUIterator::rewind() - Rewinds iterator
  • Iterator::next() - Move forward to next element
Read article
PHP / APCUIterator::rewind — DevDocs

APCUIterator::rewind

(PECL apcu >= 5.0.0)

APCUIterator::rewind Rewinds iterator

Description

public APCUIterator::rewind(): void

Rewinds back the iterator to the first element.

Parameters

This function has no parameters.

Return Values

No value is returned.

See Also

  • APCUIterator::next() - Move pointer to next item
  • Iterator::next() - Move forward to next element
Read article
PHP / APCUIterator::valid — DevDocs

APCUIterator::valid

(PECL apcu >= 5.0.0)

APCUIterator::valid Checks if current position is valid

Description

public APCUIterator::valid(): bool

Checks if the current iterator position is valid.

Parameters

This function has no parameters.

Return Values

Returns true if the current iterator position is valid, otherwise false .

See Also

  • APCUIterator::current() - Get current item
  • Iterator::valid() - Checks if current position is valid
Read article
PHP / array — DevDocs

array

(PHP 4, PHP 5, PHP 7, PHP 8)

array Create an array

Description

array(mixed ...$values): array

Creates an array. Read the section on the array type for more information on what an array is.

Parameters

values

Syntax "index => values", separated by commas, define index and values. index may be of type string or integer. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.

Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.

Return Values

Returns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is.

Examples

The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.

Example #1 array() example

<?php
$fruits = array (
    "fruits"  => array("a" => "orange", "b" => "banana", "c" => "apple"),
    "numbers" => array(1, 2, 3, 4, 5, 6),
    "holes"   => array("first", 5 => "second", "third")
);
?>

Example #2 Automatic index with array()

<?php
$array = array(1, 1, 1, 1,  1, 8 => 1,  4 => 1, 19, 3 => 13);
print_r($array);
?>

The above example will output:

Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 13
    [4] => 1
    [8] => 1
    [9] => 19
)

Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8.

This example creates a 1-based array.

Example #3 1-based index with array()

<?php
$firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);
?>

The above example will output:

Array
(
    [1] => January
    [2] => February
    [3] => March
)

As in Perl, you can access a value from the array inside double quotes. However, with PHP you'll need to enclose your array between curly braces.

Example #4 Accessing an array inside double quotes

<?php

$foo = array('bar' => 'baz');
echo "Hello {$foo['bar']}!"; // Hello baz!

?>

Notes

Note :

array() is a language construct used to represent literal arrays, and not a regular function.

See Also

  • array_pad() - Pad array to the specified length with a value
  • list() - Assign variables as if they were an array
  • count() - Counts all elements in an array or in a Countable object
  • range() - Create an array containing a range of elements
  • foreach
  • The array type
Read article
PHP / array_change_key_case — DevDocs

array_change_key_case

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

array_change_key_case Changes the case of all keys in an array

Description

array_change_key_case(array $array, int $case = CASE_LOWER): array

Returns an array with all keys from array lowercased or uppercased. Numbered indices are left as is.

Parameters

array

The array to work on

case

Either CASE_UPPER or CASE_LOWER (default)

Return Values

Returns an array with its keys lower or uppercased, or null if array is not an array.

Examples

Example #1 array_change_key_case() example

<?php
$input_array = array("FirSt" => 1, "SecOnd" => 4);
print_r(array_change_key_case($input_array, CASE_UPPER));
?>

The above example will output:

Array
(
    [FIRST] => 1
    [SECOND] => 4
)

Notes

Note :

If an array has indices that will be the same once run through this function (e.g. " keY " and " kEY "), the value that is later in the array will override other indices.

Read article