Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use array_slice() function in php ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 449
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss array_slice() in php ?

    The array_slice() function is used to for returning selected parts of an array.

    syntax of array_slice()

      array_slice(array,start,length,preserve)
    

    In the above given syntax array and start both are required parameter
    and length and preserve both are option parameter

    <?php
      //here define a variable of array
         $data = array(
          'Emp_name' => 'Joe',
          'Emp_age' => 40,
          'Emp_dep' => 'account', 
      );
    
      //here call array_slice() and pass starting point
      print_r(array_slice($data,2));
      //here pass start and length both
      print_r(array_slice($data,1,2));
    
    ?>
    

    output will come following of above example
    when you will pass only start parameter

    Array ( [Emp_dep] => account )
    

    and when you will pass start and length both parameter

    Array ( [Emp_age] => 40 [Emp_dep] => account ) 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: