pos()是PHP中的内置函数, 用于返回内部指针当前指向的数组中元素的值。返回值后, pos()函数不会递增或递减内部指针。在PHP中, 所有数组都有一个内部指针。此内部指针指向该数组中的某个元素, 称为该数组的当前元素。通常, 当前元素是数组中第一个插入的元素。
语法如下:
pos($array)参数:pos()函数接受单个参数$数组。这是我们要查找当前元素的数组。
返回值:它返回内部指针当前指向的数组中元素的值。如果数组为空, 则pos()函数将返回FALSE。
下面的程序说明了PHP中的pos()函数:
程序1:
<?php
     // input array
     $arr = array ( "Ram" , "Shyam" , "Geeta" , "Rita" );
      
     // Here pos() function returns current element.
     echo pos( $arr ). "\n" ; 
      
     // next() function increments internal pointer 
     // to point to next element i.e, Shyam.
     echo next( $arr ). "\n" ;
      
     // Printing current position element.
     echo pos( $arr ). "\n" ; 
      
     // Printing previous element of the current one.
     echo prev( $arr ). "\n" ; 
      
     // Printing end element of the array
     echo end ( $arr ). "\n" ; 
      
     // Printing current position element.
     echo pos( $arr ). "\n" ; 
?>输出如下:
Ram
Shyam
Shyam
Ram
Rita
Rita程序2:
<?php
     // input array
     $arr = array ( "P" , "6" , "M" , "F" );
      
     // Here pos() function returns current element.
     echo pos( $arr ). "\n" ; 
      
     // next() function increments internal pointer 
     // to point to next element i.e, 6.
     echo next( $arr ). "\n" ;
      
     // Printing current position element.
     echo pos( $arr ). "\n" ; 
      
     // Printing previous element of the current one.
     echo prev( $arr ). "\n" ; 
      
     // Printing end element of the array
     echo end ( $arr ). "\n" ; 
      
     // Printing current position element.
     echo pos( $arr ). "\n" ; 
?>输出如下:
P
6
6
P
F
F参考:
http://php.net/manual/en/function.pos.php

 
	![从字法上最小长度N的排列,使得对于正好为K个索引,a[i] a[i]+1](https://www.lsbin.com/wp-content/themes/begin%20lts/img/loading.png)
