Info
Content

PHP get key and value in loop


A cool little trick with foreach loops in PHP is you can get both the key and the value of associative array like so:

foreach ($array as $key => $value) {
    echo "$key=$value"; 
}

Very handy if you need to check the key of the value you are working with.

No Comments
Back to top