Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php foreach first element

foreach($array as $key => $element) {
    if ($key === array_key_first($array))
        echo 'FIRST ELEMENT!';

    if ($key === array_key_last($array))
        echo 'LAST ELEMENT!';
}
Comment

php foreach loop first element

$i = 0;
$len = count($array);
foreach ($array as $item) {
    if ($i == 0) {
        // first
    } else if ($i == $len - 1) {
        // last
    }
    // …
    $i++;
}
Comment

PREVIOUS NEXT
Code Example
Php :: Sorry, This File Type Is Not Permitted for Security Reasons 
Php :: artisan make model with migration 
Php :: php code to convert to small letter 
Php :: php go to another page 
Php :: php 3 months ago 
Php :: get all post values in php 
Php :: laravel storage check file exists 
Php :: guzzle bearer token 
Php :: php find multiple strings in string 
Php :: php foreach echo key value 
Php :: file_get_contents timeout 
Php :: remove space from string php 
Php :: npm watch laravel 
Php :: create unique filename php 
Php :: laravel add values to request 
Php :: carbon add minutes 
Php :: remove last letter php 
Php :: how to open server in php 
Php :: php timezone for manila 
Php :: 19 hours from now php 
Php :: php convert words with spaces to camelcase 
Php :: php date and time 
Php :: laravel get list of columns in a table 
Php :: twig json_encode 
Php :: php get all txt files in directory 
Php :: format uang rupiah di php 
Php :: carbon parse sunday 30 days ago 
Php :: php laravel xml to json 
Php :: set character set utf8 in pdo php 
Php :: php int min 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =