Content · Programming · PHP

PHP current() Function: Usage and Examples

Learn how PHP current works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Returns the element at the internal array pointer.

What Is current() in PHP?

Returns the element at the internal array pointer.

Its syntax is:

current(array|object $array): mixed

Parameters:

  • $array — Accepted as array|object; required argument.

Return type: mixed. If the pointer is beyond the last element it returns false, which may also be a valid array value.

Availability: Core PHP.

Example 1: Basic Usage

<?php

echo current(["red", "blue"]);

Output:

red

If the pointer is beyond the last element it returns false, which may also be a valid array value.

Example 2: A Different Input

<?php

$colors = ["red", "blue"]; next($colors); echo current($colors);

Output:

blue

If the pointer is beyond the last element it returns false, which may also be a valid array value.

Practical Example: Applying It in a Program

<?php

$prices = [12, 18, 24]; echo current($prices); next($prices); echo current($prices);

Output:

1218

If the pointer is beyond the last element it returns false, which may also be a valid array value.

Important Behavior and Edge Cases

  • Key behavior: If the pointer is beyond the last element it returns false, which may also be a valid array value.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
current()Returns the element at the internal array pointer.
reset()current() reads at the active array pointer; reset() moves the pointer to the beginning.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: If the pointer is beyond the last element it returns false, which may also be a valid array valueIf the pointer is beyond the last element it returns false, which may also be a valid array value.

Key Takeaways

  • Returns the element at the internal array pointer.
  • If the pointer is beyond the last element it returns false, which may also be a valid array value.
  • Core PHP.

Summary: If the pointer is beyond the last element it returns false, which may also be a valid array value.

Share this resourceSend this page to someone who may find it useful.