Using arrays to implement stacks and queue fighting Spirit Queue Song queue study queue

Source: Internet
Author: User
Tags php language
Array_push () can implement the PHP language stack function.

array_push()函数的使用心得1.第一个参数必须是数组。2.所有添加的数组均为索引,即数组下标。3.$num为压入后$stack所含数组元素的个数。4.使用数组的直接赋值也可以实现数组的进栈功能,例如$array$key。$num = array_push($stack"C#""Ruby"array('jsp''Asp'),array('jsp''Asp'));

Array_pop () can implement the queue function of the PHP language.

arrayarrayarrayNULL。 此外如果被调用不是一个数则会产生一个 Warning。
   
    $stack = array("orange", "banana", "apple", "raspberry");$fruit = array_pop($stack);print_r($stack);?>Array(    [0] => orange    [1] => banana    [2] => apple)

Array_shift-moves the cell at the beginning of the array to a group

arrayarray 的长度减一并将所有其它单元向前移动一位。所有的数字键名将改为从零开始计数,文字键名将不变。
****array_unshift — 在数组开头插入一个或多个单元****

int Array_unshift (array & aRray,m I x e D var [, mixed $ ...])
Array_unshift () Inserts the incoming cell at the beginning of the array. Note that the unit is inserted as a whole, because
This incoming unit will remain in the same order. All numeric key names are modified to count back from zero, and all text key names remain unchanged.


   
    $queue = array("orange", "banana");array_unshift($queue, "apple", "raspberry");print_r($queue);?>以上例程会输出:Array(    [0] => apple    [1] => raspberry    [2] => orange    [3] => banana)

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the use of arrays to implement the stack and queue, including the queue, the use of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.