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 :: php laravel dump 
Php :: laravel collection times 
Php :: php curl empty response 
Php :: json_encode alternative 
Php :: function inside model laravel 
Php :: php string random 
Php :: get taxonomy name in taxonomy page wordpress dev 
Php :: magento2 get full details of order collection 
Php :: do artisan laravel in code 
Php :: laravel has many 
Php :: laravel create on model 
Php :: laravel on cascade set null 
Php :: change default user table name laravel 
Php :: connect rabbitMQ 
Php :: send mail using php mail function on localhost using xampp server 
Php :: Remove class from body tag in wordpress 
Php :: php implode associative array 
Php :: twig log variable 
Php :: wordpress nav menu align right 
Php :: convert php array to javascript json laravel 
Php :: php if time is greater than 
Php :: php url exists valid 
Php :: php round nearest half 
Php :: php object into nested json object 
Php :: php object is empty 
Php :: active page in laravel 
Php :: echo php in html 
Php :: codeigniter sanitize input field 
Php :: how to fetch the sum of column in php mysql 
Php :: php docker offical apache 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =