How to Get First 10 Elements of Array in PHP?
Hello Artisan,
This tutorial will provide an example of php array get first 10 elements. you will learn php array get 10 first element value. if you want to see an example of how to get 10 first element of array in php then you are in the right place. if you want to see an example of php get 10 first key of array example then you are in the right place.
we will use array_slice() function to get first 10 elements of array in php. so, let's see the simple code of how to get first 10 values in php array.
Example:
index.php
<?php
$myArray = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"];
$firstElems = array_slice($myArray, 0, 10);
var_dump($firstElems);
?>
Output:
array(10) {
[0]=> string(3) "One"
[1]=> string(3) "Two"
[2]=> string(5) "Three"
[3]=> string(4) "Four"
[4]=> string(4) "Five"
[5]=> string(3) "Six"
[6]=> string(5) "Seven"
[7]=> string(5) "Eight"
[8]=> string(4) "Nine"
[9]=> string(3) "Ten"
}
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get First 3 Elements of Array in PHP?
- How to Get First 2 Elements of Array in PHP?
- How to Get Last 10 Elements of Array in PHP?
- How to Get Last 5 Elements of Array in PHP?
- How to Get Last 3 Elements of Array in PHP?
- How to Get Last 2 Elements of Array in PHP?
- How to Get Random Value from an Array in PHP?
- How to Get Last Element of Array in PHP?
- How to Get First Element of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?