U
U
Uzair Izha2015-11-17 09:26:15
PHP
Uzair Izha, 2015-11-17 09:26:15

How to extract a certain number of elements from an array?

I have an array $caon in which there are 10 values, 1,2,3,4,5,6,7,8,9,10 how, for example, to extract only 5 from this array? for example to another array.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cat Anton, 2015-11-17
@27cm

$result = array_slice($caon, 0, 5);
php.net/manual/en/function.array-slice.php

S
Sergey, 2015-11-17
@Robotkos

foreach ($caon as $key => $res) {
$output[] = array_slice($res, 0 , 5);
}
will pull the first 5 values

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question