NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - array_slice

Trieda

Koreň \ Bez triedy

Metóda - array_slice

(PHP 4, PHP 5, PHP 7)

This function creates a slice of a given length from a given array containing elements starting at a given position (offset).

Procedurálne

  • function array_slice (array $array, int $offset) : array

Parametre

NázovDátový typPredvolená hodnotaPopis
$arrayarray

The input array, from which the slice should be made.

$offsetint

The beginning (offset) of the slice. If the given value is positive, the offset relates to the beginning of the array, otherwise, the given offset relates to the end of the array, meaning the elements will be taken in the direction to the beginning of the

Mávratovej hodnoty

Vracia: array

The slice. An empty array is returned, if the offset is larger than the length of the input array.

Príklady

This example outputs an array with items labeled as 2nd and 3rd .

<?php

$arr = array('1st item', '2nd item', '3rd item', '4th item', '5th item');
$out = array_slice($arr, 1, 2);
var_dump($out);

Súvisiace manuály

      • function array_splice (array &$input, int $offset, int $length = count($input), mixed $replacement = array()) : array
      Aktivity