PHP Getting Started Tutorial: PHP array_slice () Function Example Tutorial

Source: Internet
Author: User

PHP Array_slice () Function Example Tutorial

Definitions and usage
The Array_slice () function returns the selected part of the array.

Grammar
Array_slice (Array,start,length,preserve)
 
  
  
parameter description
array required. Specifies an array
start
length
preserve
 
  
  
Tips and Instructions
Note: If the array has a keychain, the returned array will allways the maintenance key. (See for example 4)




Example 1

 <?php $a =array (0=> "Dog",1=> "Cat",2=> "Horse",3=> "Bird");

  Print_r (Array_slice ($a, 1,2)); 
   
 output results. 
 
 Array ([0] => Cat [1] => horse) 
 
     
     

Example 2
with negative startup parameters :

 

 <?php $a =array (0=> "Dog",1=> "Cat",2=> "Horse",3=> "Bird"); Print_r (ARRAY_SL

     Ice ($a, -2,1)); 
   
 output results. 
 
 Array ([0] => horse) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.