Chaitanya Lakshmi
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook

What is array_shift?

2/17/2012

1 Comment

 
array_shift — Shift an element off the beginning of array
Returns the shifted value, or NULL if array is empty or is not an array.

Example:
<?php
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack);
print_r($stack);
?>

O/P:
Array
(
    [0] => banana
    [1] => apple
    [2] => raspberry
)
1 Comment
Paul
9/27/2012 05:55:10 am

I've found plenty of articles like this explaining what it does, but not why. What use is it? Why would you want to get rid of the orange out of the array (in your example)?

My only line of thinking applies to my own case where I have a text file with many lines which are each delimited by the pipe character. array_shift would, effectively, eliminate the first line so... could I use that first line to store the field names - rather like in Excel when you sort a table and your tell it that the first row is the header row?

Reply



Leave a Reply.

    Archives

    April 2012
    March 2012
    February 2012

    Categor

    All
    Ajax
    Api
    Cross Site Scripting
    Css
    Curl
    Design Patterns
    Drupal
    Exception Handling
    Htaccess
    Html
    Javascript
    Jquery
    Json
    Linux
    Mysql
    Oops
    Php
    Regular Expressions
    Web 2.0
    Webservices
    Wordpress
    Xhtml

    RSS Feed

Powered by Create your own unique website with customizable templates.