Doubts about PHP characters and arrays

Source: Internet
Author: User
Questions about PHP characters and arrays
$str = "123456";
Var_dump ($str ["abc"]);

Why the result is the first character and not the null and I unset ($str ["ABC"]) and I'm not suggesting that subscript.
------Solution--------------------
String is not an array, only position, no subscript and association key
Array-related functions cannot be used for strings

So the "ABC" in $STR ["ABC"] is converted to a value of 0
For $str = "123456"; In terms of $STR ["ABC"] is $str [0], so get 1

Although you can write a location that accesses a string $str [$i]
But to avoid ambiguity, PHP suggests you write this $str {$i}
------Solution--------------------
Manual comparison Operators Section
------------------------------------------
Var_dump (0 = = "a"); 0 = = 0-True
Var_dump ("1" = = "01"); 1 = = 1-True
Var_dump ("1" = = "1e0"); 1 = = 1-True
Switch ("a") {
Case 0:
echo "0";
Break
Case ' a ':///Never reached because "a" is already matched with 0
echo "a";
Break
}
?>
------------------------
Switch, the example is obvious.

The string index cannot be "string", but PHP handles it "intelligently" to become 0
  • Related Article

    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.