About parameter problems with PHP foreach

Source: Internet
Author: User
Tags php foreach
$arr = array();foreach ($arr as $key => $value) {    if (!isset($key)) {        echo 'haha';    }}

When the $key does not exist, the output is haha, but the actual operation why does nothing output?

Reply content:

$arr = array();foreach ($arr as $key => $value) {    if (!isset($key)) {        echo 'haha';    }}

When the $key does not exist, the output is haha, but the actual operation why does nothing output?

No access to foreach

$keyHow is it that there is no way to be traversed?

Logic problem, definitely can't get into if

First the array is empty, does not enter foreach, and second, there is no !isset($key) case

Upstairs is right, your array is empty, the program will not enter the Foreach loop.

$arr has a value and does not enter the IF

$arr = array('key1'=>'hello',3,4=>'34',4);foreach ($arr as $key => $value) {    if (!isset($key)) {        echo 'haha';    }else{        echo $key.' ';    }}//print: key1 0 4 5
  • 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.