Skip to content

PHP Array Functions: current() and pos()

current (): Finds the element at the pointer to the array.

pos (): Finds the element at the pointer to the array.


  $LIST = ["alex","maria","rick","allen","bob"];

  print "<pre>";
  print_r($LIST);
  print "</pre>";


  $LIST_CURRENT = current($LIST);

  print "<pre>";
  print_r("current value: " . $LIST_CURRENT);
  print "</pre>";
Array
(
    [0] => alex
    [1] => maria
    [2] => rick
    [3] => allen
    [4] => bob
)
 current value: alex 

  $LIST = ["alex","maria","rick","allen","bob"];

  print "<pre>";
  print_r($LIST);
  print "</pre>";


  $LIST_POS = pos($LIST);

  print "<pre>";
  print_r("pos value: " . $LIST_POS);
  print "</pre>";
Array
(
    [0] => alex
    [1] => maria
    [2] => rick
    [3] => allen
    [4] => bob
)

 pos value: alex 

  $LIST = array(array("allen","bob"),"alex","maria","rick");

  print "<pre>";
  print_r($LIST);
  print "</pre>";


  $LIST_CURRENT = current($LIST);

  print "<pre>";
  print_r($LIST_CURRENT);
  print "</pre>";
Array
(
    [0] => Array
        (
            [0] => allen
            [1] => bob
        )

    [1] => alex
    [2] => maria
    [3] => rick
)

 Array
(
    [0] => allen
    [1] => bob
) 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: