T
T
temp54232014-09-20 20:31:30
PHP
temp5423, 2014-09-20 20:31:30

How to display the third element of an array?

we have an array

Array
(
    [0] => 1
    [5] => 10
    [1] => 110
    [2] => 123
    [3] => 234
    [4] => 345
)

how to get the third element of the array i.e. 110?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
KorsaR-ZN, 2014-09-20
@temp5423

echo array_slice($array, 2, 1)[0];
// or
echo array_values($array)[2];

The first option is better

A
andreyqin, 2014-09-20
@andreyqin

$array[1]?

K
kompi, 2014-09-20
@kompi

By key directly or through a loop with a counter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question