Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php array subset by slicing


<?php
$input = array("a", "b", "c", "d", "e");

$output = array_slice($input, 2);      // returns "c", "d", and "e"
$output = array_slice($input, -2, 1);  // returns "d"
$output = array_slice($input, 0, 3);   // returns "a", "b", and "c"

// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>
/*
Array
(
    [0] => c
    [1] => d
)
Array
(
    [2] => c
    [3] => d
)
*/
Comment

PREVIOUS NEXT
Code Example
Php :: laravel vue 
Php :: yesterday php 
Php :: symnfony bearer token 
Php :: how to print string plus variable in php 
Php :: laravel where not equal 
Php :: email or phone required in laravel 
Php :: laravel query order by relation 
Php :: 301 redirect 
Php :: php fpm test 
Php :: Laravel - Query Builder Raw Query selectRaw 
Php :: laravel resource set status code 
Php :: laravel get id from insert 
Php :: wp reserved image size names 
Php :: date format with t and z php 
Php :: php get first character of each word 
Php :: specification migration laravel 
Php :: laravel url download file 
Php :: convert_uudecode (PHP 5, PHP 7, PHP 8) convert_uudecode — Decode a uuencoded string 
Php :: excel date format in php 
Php :: Stored Procedures in Laravel 
Php :: laravel latest from relationship 
Php :: on running php file showing code instead of view 
Php :: php named parameters 
Php :: php add array to array 
Php :: using php to add numbers in html form 
Php :: get all class methods php 
Php :: multi theme laravel 
Php :: update column type laravel migration 
Php :: php one hour in the future 
Php :: php stop loading page 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =