$map = [ "name" =>"Peter", "age" =>26, "gender" =>"male" ]; echo $map["name"]; // 輸出:Peter echo $map["age"]; // 輸出:26 echo $map["gender"]; // 輸出:male如上所示,我們可以通過
$map = [ "name" =>"Peter", "age" =>26, "gender" =>"male" ]; $map["age"] = 27; echo $map["age"]; // 輸出:27如上所示,我們通過鍵名
"age"
獲取到原本保存的值為26
,然后將其覆蓋為27
。當(dāng)我們再次通過"age"
鍵名獲取值時(shí),會得到27
。這也說明了$map = [ "name" =>"Peter", "age" =>26, "gender" =>"male" ]; foreach ($map as $key =>$value) { echo "$key: $value如上所示,我們使用
"; } // 輸出: // name: Peter // age: 26 // gender: male
$key
表示當(dāng)前循環(huán)的鍵名,$value
表示對應(yīng)的值。上一篇php get抓取
下一篇php gmt 0800