What's the difference between these two sentences?

Source: Internet
Author: User
$arr = $db->getrows ("SELECT * from Pinglun");

What's the difference between these two?
foreach ($arr as $k = = $v) {

foreach ($arr as $v) {

I see the output is the same.

Why do you want to add a =


Reply to discussion (solution)

Two sentences are the same, just
foreach ($arr as $k = = $v) {
You can read array subscript with $k
foreach ($arr as $v) {
This sentence is not

If you only care about values, the same

If you still care about key, it is different, many times we need to deal with the value of close-up key alone need to use $k=> $v

If you don't have to $k, then it's the same.

Process is the same as whether you need to get the array key

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.