PHP current() function with example

PHP current() function with example

PHP current() work: Here, we will find out about the current() work with the example in PHP.

PHP current() work

A cluster in PHP has a present pointer which focuses on the primary component as a matter of course, current() work is utilized to get the present components of an exhibit. It acknowledges an exhibit and returns its present component.

Syntax:

current(array); 

Note:

  • In a cluster which contains keys and values, it returns just value, not a key.
  • current() returns just the present component, it doesn’t move the pointer to next component.

Example:

    Input:
    $arr1 = array(13, 20, 30, 40, 50);
    Output:
    13

    Input:
    $arr2 = array("name" => "Kishan", "age" => 21, "Gender" => "Male");
    Output:
    Kishan

PHP Code:

<?php
    $arr1 = array(13, 20, 30, 40, 50);
    $arr2 = array("name" => "Kishan", "age" => 21, "Gender" => "Male");
    
    //printing current element
    echo current($arr1). "\n";
    echo current($arr2). "\n";
?>

Output

13
Kishan

Recent Posts

error: Alert: Content is protected!!