Answers for "php get index of first element in array"

PHP
6

get index of element in array php

$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array);   // $key = 1;
Posted by: Guest on September-24-2020
1

first item in array php

$firstItem = array_shift($array);
Posted by: Guest on May-24-2020
6

php get first element of array

$colors = array(2=>"blue",3 =>"green",1=>"red");
$firstValue = reset($colors); //blue
$firstKey = key($colors); //2
Posted by: Guest on October-30-2019
0

get first element of array php

array_pop(array_reverse($array));
Posted by: Guest on September-21-2021

Code answers related to "php get index of first element in array"

Browse Popular Code Answers by Language