php foreach index
snippet in php

php foreach index

user6808

foreach($array as $key=>$value) {
    // do stuff
}

php foreach get current index

user9506

$index = 0;
foreach($data as $key=>$val) {
    // Use $key as an index, or...

    // ... manage the index this way..
    echo "Index is $index\n";
    $index++;
}

php foreach index

user9373

foreach($array as $key=>$value) {
    // do stuff
}

php foreach index

user5517

Blog::whereYear('created_at', 2017)->get();