{"id":630,"date":"2025-06-11T11:22:20","date_gmt":"2025-06-11T03:22:20","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/sjjg\/630.html"},"modified":"2025-06-11T11:22:20","modified_gmt":"2025-06-11T03:22:20","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-php-%e4%b8%ad%e9%81%8d%e5%8e%86%e4%b8%80%e4%b8%aa%e5%af%b9%e8%b1%a1","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/630.html","title":{"rendered":"\u5982\u4f55\u5728 PHP \u4e2d\u904d\u5386\u4e00\u4e2a\u5bf9\u8c61"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; PHP &#20013;&#36941;&#21382;&#19968;&#20010;&#23545;&#35937;&#21487;&#20197;&#36890;&#36807;&#22810;&#31181;&#26041;&#24335;&#23454;&#29616;&#65292;&#20855;&#20307;&#21462;&#20915;&#20110;&#23545;&#35937;&#30340;&#32467;&#26500;&#21644;&#35774;&#35745;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#24120;&#35265;&#30340;&#26041;&#27861;&#65306;<\/p>\n<h3>&#26041;&#27861;&#19968;&#65306;&#20351;&#29992; <code>foreach<\/code> &#24490;&#29615;<\/h3>\n<p>&#22914;&#26524;&#20320;&#30340;&#23545;&#35937;&#26159;&#19968;&#20010;&#25968;&#32452;&#65288;&#21363;&#38190;&#20540;&#23545;&#65289;&#65292;&#21487;&#20197;&#20351;&#29992; <code>foreach<\/code> &#24490;&#29615;&#26469;&#36941;&#21382;&#23427;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\nclass Person {\n    public $name;\n    public $age;\n\n    public function __construct($name, $age) {\n        $this-&gt;name = $name;\n        $this-&gt;age = $age;\n    }\n}\n\n$person1 = new Person('Alice', 30);\n$person2 = new Person('Bob', 25);\n\n$arrayOfPeople = [$person1, $person2];\n\nforeach ($arrayOfPeople as $person) {\n    echo \"Name: \" . $person-&gt;name . \", Age: \" . $person-&gt;age . \"n\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#26041;&#27861;&#20108;&#65306;&#20351;&#29992; <code>IteratorAggregate<\/code> &#25509;&#21475;<\/h3>\n<p>&#22914;&#26524;&#20320;&#30340;&#23545;&#35937;&#23454;&#29616;&#20102; <code>IteratorAggregate<\/code> &#25509;&#21475;&#65292;&#20320;&#21487;&#20197;&#30452;&#25509;&#20351;&#29992; <code>foreach<\/code> &#24490;&#29615;&#26469;&#36941;&#21382;&#23427;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\ninterface IteratorAggregate {\n    public function getIterator();\n}\n\nclass Person implements IteratorAggregate {\n    private $people = [];\n\n    public function __construct() {\n        $this-&gt;people[] = new Person('Alice', 30);\n        $this-&gt;people[] = new Person('Bob', 25);\n    }\n\n    public function getIterator() {\n        return new ArrayIterator($this-&gt;people);\n    }\n}\n\n$personCollection = new Person();\n\nforeach ($personCollection as $person) {\n    echo \"Name: \" . $person-&gt;name . \", Age: \" . $person-&gt;age . \"n\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#26041;&#27861;&#19977;&#65306;&#20351;&#29992; <code>ReflectionClass<\/code><\/h3>\n<p>&#22914;&#26524;&#20320;&#38656;&#35201;&#36941;&#21382;&#19968;&#20010;&#31867;&#30340;&#25152;&#26377;&#23646;&#24615;&#65292;&#21487;&#20197;&#20351;&#29992; <code>ReflectionClass<\/code> &#31867;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\nclass Person {\n    public $name;\n    public $age;\n\n    public function __construct($name, $age) {\n        $this-&gt;name = $name;\n        $this-&gt;age = $age;\n    }\n}\n\n$person = new Person('Alice', 30);\n\n$reflection = new ReflectionClass($person);\n\nforeach ($reflection-&gt;getProperties() as $property) {\n    if ($property-&gt;isPublic()) {\n        echo \"Property Name: \" . $property-&gt;getName() . \", Value: \" . $property-&gt;getValue($person) . \"n\";\n    }\n}\n?&gt;<\/code><\/pre>\n<h3>&#31034;&#20363;&#20195;&#30721;&#30456;&#20851;&#27493;&#39588;<\/h3>\n<p>&#20551;&#35774;&#20320;&#26377;&#19968;&#20010;&#21517;&#20026; <code>User<\/code> &#30340;&#31867;&#65292;&#24182;&#19988;&#20320;&#24819;&#36941;&#21382;&#23427;&#30340;&#25152;&#26377;&#23646;&#24615;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\nclass User {\n    public $username;\n    public $email;\n    public $age;\n\n    public function __construct($username, $email, $age) {\n        $this-&gt;username = $username;\n        $this-&gt;email = $email;\n        $this-&gt;age = $age;\n    }\n}\n\n$user = new User('john_doe', 'john@example.com', 30);\n\n\/\/ &#20351;&#29992; ReflectionClass &#36941;&#21382;&#23646;&#24615;\n$reflection = new ReflectionClass($user);\n\nforeach ($reflection-&gt;getProperties() as $property) {\n    if ($property-&gt;isPublic()) {\n        echo \"Property Name: \" . $property-&gt;getName() . \", Value: \" . $property-&gt;getValue($user) . \"n\";\n    }\n}\n?&gt;<\/code><\/pre>\n<p>&#36816;&#34892;&#36825;&#27573;&#20195;&#30721;&#23558;&#36755;&#20986;&#65306;<\/p>\n<pre><code>Property Name: username, Value: john_doe\nProperty Name: email, Value: john@example.com\nProperty Name: age, Value: 30<\/code><\/pre>\n<p>&#36890;&#36807;&#36825;&#20123;&#26041;&#27861;&#65292;&#20320;&#21487;&#20197;&#26377;&#25928;&#22320;&#36941;&#21382; PHP &#23545;&#35937;&#30340;&#21508;&#31181;&#24418;&#24335;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#27010;&#35272;<\/h2><p>&#36941;&#21382;PHP&#20013;&#30340;&#23545;&#35937;&#26159;&#19968;&#31181;&#24120;&#35265;&#30340;&#20219;&#21153;&#65292;&#20351;&#24320;&#21457;&#20154;&#21592;&#33021;&#22815;&#36941;&#21382;&#23545;&#35937;&#30340;&#23646;&#24615;&#24182;&#25805;&#32437;&#25968;&#25454;&#12290;&#26412;&#25945;&#31243;&#23558;&#28085;&#30422;&#19981;&#21516;&#30340;&#26041;&#27861;&#26469;&#36941;&#21382;PHP&#23545;&#35937;&#30340;&#23646;&#24615;&#65292;&#20174;&#22522;&#26412;&#21040;&#39640;&#32423;&#25216;&#26415;&#12290;<\/p><h2>&#29702;&#35299;PHP&#23545;&#35937;<\/h2><p>&#22312;&#24320;&#22987;&#36845;&#20195;&#20043;&#21069;&#65292;&#35753;&#25105;&#20204;&#20808;&#20102;&#35299;&#19968;&#19979;&#20160;&#20040;&#26159;PHP&#20013;&#30340;&#23545;&#35937;&#12290;&#22312;PHP&#20013;&#65292;&#23545;&#35937;&#26159;&#23545;&#31867;&#30340;&#23454;&#20363;&#21270;&#12290;&#19968;&#20010;&#31867;&#23450;&#20041;&#20102;&#23545;&#35937;&#30340;&#23646;&#24615;&#21644;&#34892;&#20026;&#12290;&#19968;&#26086;&#21019;&#24314;&#20102;&#19968;&#20010;&#23545;&#35937;&#65292;&#25105;&#20204;&#21487;&#33021;&#24076;&#26395;&#23545;&#20854;&#23646;&#24615;&#36827;&#34892;&#21508;&#31181;&#25805;&#20316;&#65292;&#20363;&#22914;&#36755;&#20986;&#36825;&#20123;&#23646;&#24615;&#12289;&#20462;&#25913;&#20540;&#25110;&#36827;&#34892;&#35745;&#31639;&#12290;<\/p><pre><code>&lt;?php\nclass Product {\n  public $name;\n  public $price;\n\n  public function __construct($name, $price) {\n    $this-&gt;name = $name;\n    $this-&gt;price = $price;\n  }\n}\n\n$product = new Product('Apple', 0.32);\n?&gt;\n<\/code><\/pre><h2>&#36941;&#21382;&#23545;&#35937;&#30340;&#23646;&#24615;<\/h2><p>&#20026;&#20102;&#36941;&#21382;&#23545;&#35937;&#30340;&#23646;&#24615;&#65292;PHP &#25552;&#20379;&#20102;&#22810;&#31181;&#26500;&#36896;&#21644;&#20989;&#25968;&#65292;&#20363;&#22914;&#65306;<code>foreach<\/code>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<code>get_object_vars<\/code>&#21644;&#20320;&#19968;&#26679;&#65292;&#25105;&#20063;&#26159;&#29992;&#20013;&#25991;&#22238;&#22797;&#30340;&#12290;<code>Iterator<\/code>&#23545;&#19981;&#36215;&#65292;&#25105;&#26410;&#33021;&#29702;&#35299;&#24744;&#30340;&#38382;&#39064;&#65292;&#35831;&#37325;&#26032;&#25551;&#36848;&#24744;&#30340;&#38656;&#27714;&#12290;<\/p><h3>&#20351;&#29992;foreach&#12290;<\/h3><p><code>foreach<\/code>&#36941;&#21382;&#21487;&#35775;&#38382;&#30340;&#23646;&#24615;&#30340;&#26368;&#31616;&#21333;&#26041;&#27861;&#26159;&#20160;&#20040;&#65311;<\/p><pre><code>&lt;?php\nforeach ($product as $key =&gt; $value) {\n  echo \"$key: $valuen\";\n}\n\/\/ Output:\n\/\/ name: Apple\n\/\/ price: 0.32\n?&gt;\n<\/code><\/pre><p>&#35813;&#20195;&#30721;&#36755;&#20986;&#25152;&#26377;&#21487;&#35775;&#38382;&#23646;&#24615;&#30340;&#21517;&#31216;&#21644;&#20540;&#12290;<code>Product<\/code>&#25105;&#20204;&#20043;&#21069;&#21019;&#24314;&#30340;&#23545;&#35937;&#12290;&lsquo;&#21487;&#35775;&#38382;&rsquo;&#23646;&#24615;&#26159;&#25351;&#37027;&#20123;&#26159;&#20844;&#24320;&#30340;&#65292;&#25110;&#32773;&#22312;&#23545;&#35937;&#30340;&#20316;&#29992;&#22495;&#20869;&#20320;&#21487;&#20197;&#35775;&#38382;&#30340;&#12290;<\/p><h3>&#20351;&#29992; get_object_vars()<\/h3><p>&#21478;&#19968;&#31181;&#33719;&#21462;&#23545;&#35937;&#25152;&#26377;&#21487;&#35775;&#38382;&#23646;&#24615;&#30340;&#26041;&#27861;&#26159;&#20351;&#29992;&#12290;<code>get_object_vars()<\/code>&#20989;&#25968;&#65292;&#36820;&#22238;&#19968;&#20010;&#20851;&#32852;&#25968;&#32452;&#12290;<\/p><pre><code>&lt;?php\n$properties = get_object_vars($product);\nforeach ($properties as $key =&gt; $value) {\n  echo \"$key: $valuen\";\n}\n\/\/ Similar output as before\n?&gt;\n<\/code><\/pre><p>&#35831;&#27880;&#24847;<code>get_object_vars()<\/code>&#20063;&#21482;&#36820;&#22238;&#22522;&#20110;&#35843;&#29992;&#28857;&#19978;&#19979;&#25991;&#30340;&#21487;&#35775;&#38382;&#23646;&#24615;&#12290;<\/p><h2>&#35775;&#38382;&#31169;&#26377;&#21644;&#21463;&#20445;&#25252;&#30340;&#23646;&#24615;<\/h2><p>&#26377;&#26102;&#65292;&#36941;&#21382;&#20844;&#24320;&#23646;&#24615;&#19981;&#36275;&#20197;&#28385;&#36275;&#38656;&#27714;&#12290;&#20320;&#38656;&#35201;&#35775;&#38382;&#31169;&#26377;&#25110;&#21463;&#20445;&#25252;&#30340;&#23646;&#24615;&#12290;&#35201;&#23454;&#29616;&#36825;&#19968;&#28857;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;&#21453;&#23556;&#25110;&#22312;&#20320;&#30340;&#31867;&#20013;&#25552;&#20379;&#36825;&#20123;&#23646;&#24615;&#30340;&#33258;&#23450;&#20041;&#26041;&#27861;&#12290;<\/p><h3>&#20351;&#29992;&#21453;&#23556;<\/h3><p>&#20320;&#21487;&#20197;&#20351;&#29992;PHP&#30340;Reflection&#31867;&#26469;&#26816;&#26597;&#31867;&#21644;&#23545;&#35937;&#12290;<\/p><pre><code>&lt;?php\n$reflection = new ReflectionObject($product);\n$properties = $reflection-&gt;getProperties();\n\nforeach ($properties as $property) {\n  $property-&gt;setAccessible(true);\n  echo $property-&gt;getName() . ': ' . $property-&gt;getValue($product) . \"n\";\n}\n\/\/ All properties, including private and protected, will be outputted if they exist\n?&gt;\n<\/code><\/pre><p>&#21453;&#23556;&#20801;&#35768;&#24744;&#35775;&#38382;&#31169;&#26377;&#21644;&#21463;&#20445;&#25252;&#30340;&#23646;&#24615;&#65292;&#20294;&#24212;&#35880;&#24910;&#20351;&#29992;&#65292;&#22240;&#20026;&#36825;&#36829;&#21453;&#20102;&#23553;&#35013;&#21407;&#21017;&#12290;<\/p><h3>&#23454;&#29616;&#36845;&#20195;&#22120;&#25509;&#21475;<\/h3><p>&#22914;&#26524;&#20320;&#24819;&#35201;&#36941;&#21382;&#31169;&#26377;&#25110;&#21463;&#20445;&#25252;&#30340;&#23646;&#24615;&#65292;&#25110;&#32773;&#25552;&#20379;&#33258;&#23450;&#20041;&#36845;&#20195;&#36923;&#36753;&#65292;&#20320;&#21487;&#20197;&#23454;&#29616;&#36825;&#20010;&#25509;&#21475;&#12290;<code>Iterator<\/code>&#23545;&#19981;&#36215;&#65292;&#25105;&#19981;&#22826;&#26126;&#30333;&#20320;&#30340;&#24847;&#24605;&#65292;&#35831;&#37325;&#26032;&#25551;&#36848;&#19968;&#19979;&#20320;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><pre><code>&lt;?php\nclass ProductI implements Iterator {\n  private $properties = array();\n  private $position = 0;\n\n  public function __construct($name, $price) {\n    $this-&gt;properties['name'] = $name;\n    $this-&gt;properties['price'] = $price;\n    $this-&gt;position = 0;\n  }\n\n  public function current() {\n    return $this-&gt;properties[array_keys($this-&gt;properties)[$this-&gt;position]];\n  }\n  public function key() {\n    return array_keys($this-&gt;properties)[$this-&gt;position];\n  }\n  public function next() {\n    ++$this-&gt;position;\n  }\n  public function rewind() {\n    $this-&gt;position = 0;\n  }\n  public function valid() {\n    return isset(array_keys($this-&gt;properties)[$this-&gt;position]);\n  }\n}\n\n$productI = new ProductI('Banana', 0.22);\nforeach ($productI as $key =&gt; $value) {\n  echo \"$key: $valuen\";\n}\n\/\/ Outputs the properties and values of the ProductI object\n?&gt;\n<\/code><\/pre><p>&#36825;&#31181;&#36845;&#20195;&#27169;&#24335;&#25552;&#20379;&#20102;&#26356;&#22823;&#30340;&#25511;&#21046;&#26435;&#65292;&#20294;&#38656;&#35201;&#32534;&#20889;&#26356;&#22810;&#30340;&#20195;&#30721;&#65292;&#22240;&#20026;&#20320;&#24517;&#39035;&#23450;&#20041;&#30001;&#36845;&#20195;&#22120;&#25509;&#21475;&#24378;&#21046;&#25191;&#34892;&#30340;&#27599;&#20010;&#26041;&#27861;&#12290;<\/p><h2>&#23545;&#21487;&#31359;&#36234;&#23545;&#35937;&#30340;&#26356;&#28145;&#20837;&#30740;&#31350;<\/h2><p>&#23545;&#19981;&#36215;&#65292;&#25105;&#26080;&#27861;&#29702;&#35299;&#36825;&#21477;&#35805;&#12290;&#35831;&#37325;&#26032;&#25551;&#36848;&#24744;&#30340;&#38382;&#39064;&#25110;&#25552;&#20379;&#26356;&#22810;&#20449;&#24687;&#20197;&#20415;&#25105;&#33021;&#26356;&#22909;&#22320;&#24110;&#21161;&#24744;&#12290;<code>Traversable<\/code>&#25509;&#21475;&#26159;&#25152;&#26377;&#21487;&#34987;&#20351;&#29992;PHP&#23545;&#35937;&#36941;&#21382;&#30340;&#22522;&#30784;&#25509;&#21475;&#12290;<code>foreach<\/code>. &#26681;&#25454;&#35774;&#35745;&#65292;&#23427;&#19981;&#33021;&#21333;&#29420;&#23454;&#26045;&#65292;&#24212;&#36890;&#36807;&#20197;&#19979;&#26041;&#24335;&#23454;&#29616;&#65306;<code>Iterator<\/code>&#21734;&#65292;&#26159;&#21527;&#65311;<code>IteratorAggregate<\/code>&#24050;&#25910;&#21040;&#25351;&#20196;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><p>&#23454;&#26045;<code>IteratorAggregate<\/code>&#21487;&#20197;&#24110;&#21161;&#20445;&#25345;&#24744;&#30340;&#31867;&#20195;&#30721;&#25972;&#27905;&#65292;&#23558;&#36845;&#20195;&#36923;&#36753;&#22996;&#25176;&#32473;&#21478;&#19968;&#20010;&#31867;&#12290;&#20197;&#19979;&#26159;&#20351;&#29992;&#23427;&#30340;&#26041;&#27861;&#65306;<\/p><pre><code>&lt;?php\nclass ProductAggregate implements IteratorAggregate {\n  private $properties;\n\n  public function __construct($props) {\n    $this-&gt;properties = $props;\n  }\n\n  public function getIterator() {\n    return new ArrayIterator($this-&gt;properties);\n  }\n}\n\n$productAggregate = new ProductAggregate(['name' =&gt; 'Cherry', 'price' =&gt; 0.50]);\nforeach ($productAggregate as $key =&gt; $value) {\n  echo \"$key: $valuen\";\n}\n\/\/ Outputs the properties of ProductAggregate object\n?&gt;\n<\/code><\/pre><p>&#36825;&#31181;&#26041;&#27861;&#39640;&#25928;&#22320;&#32467;&#21512;&#20102;&#23553;&#35013;&#21644;&#36845;&#20195;&#12290;<\/p><h2>&#32467;&#35770;&#12290;<\/h2><p>&#36941;&#21382;PHP&#23545;&#35937;&#30340;&#36807;&#31243;&#26159;&#19968;&#31181;&#28789;&#27963;&#30340;&#27969;&#31243;&#65292;&#21487;&#20197;&#26681;&#25454;&#25152;&#38656;&#30340;&#35775;&#38382;&#21644;&#25511;&#21046;&#32423;&#21035;&#36827;&#34892;&#22810;&#31181;&#26041;&#24335;&#25191;&#34892;&#12290;&#29702;&#35299;&#27599;&#31181;&#36845;&#20195;&#26041;&#27861;&#20043;&#38388;&#30340;&#24046;&#24322;&#21487;&#20197;&#24110;&#21161;&#24320;&#21457;&#20154;&#21592;&#32534;&#20889;&#26356;&#26377;&#25928;&#19988;&#23433;&#20840;&#30340;&#23545;&#35937;-&#38754;&#21521;&#23545;&#35937;&#30340;PHP&#20195;&#30721;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;PHP&#20013;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;<code>foreach<\/code>&#24490;&#29615;&#26469;&#36941;&#21382;&#20219;&#20309;&#20855;&#26377;&#21487;&#36845;&#20195;&#23646;&#24615;&#30340;&#23545;&#35937;&#12290;&#20363;&#22914;&#65292;&#22914;&#26524;&#20320;&#26377;&#19968;&#20010;&#25968;&#32452;&#25110;&#32773;&#19968;&#20010;&#23545;&#35937;&#65292;&#20320;&#21487;&#20197;&#20687;&#36825;&#26679;&#36941;&#21382;&#23427;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\n\/\/ &#31034;&#20363;&#65306;&#20551;&#35774;&#25105;&#20204;&#26377;&#22914;&#19979;&#23545;&#35937;\n$object = array(\n    'name' =&gt; 'John',\n    'age'  =&gt; 30,\n);\n\n\/\/ &#20351;&#29992; foreach &#24490;&#29615;&#36941;&#21382;&#23545;&#35937;&#30340;&#38190;&#21644;&#20540;\nforeach ($object as $key =&gt; $value) {\n    echo \"$key: $valuen\";\n}\n<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;<code>$object<\/code> &#26159;&#19968;&#20010;&#23545;&#35937;&#65292;&#23427;&#30340; <code>__get()<\/code> &#20989;&#25968;&#36820;&#22238;&#20102;&#20854;&#20869;&#37096;&#30340;&#38190;&#20540;&#23545;&#65288;&#21363;&#25968;&#32452;&#65289;&#12290;<code>foreach<\/code>&#24490;&#29615;&#36890;&#36807; <code>$key<\/code> &#21644; <code>$value<\/code> &#35775;&#38382;&#36825;&#20123;&#38190;&#20540;&#23545;&#12290;<\/p>\n<p>&#27880;&#24847;&#65306;&#34429;&#28982;&#36825;&#20010;&#20363;&#23376;&#20351;&#29992;&#20102;&#19968;&#20010;&#31616;&#21333;&#30340;&#23545;&#35937;&#65292;&#20294;&#20320;&#21487;&#20197;&#29992;&#21516;&#26679;&#30340;&#26041;&#27861;&#36941;&#21382;&#20219;&#20309;&#21487;&#20197;&#36845;&#20195;&#30340;&#23545;&#35937;&#65292;&#22914;&#25968;&#32452;&#12289;&#23481;&#22120;&#31561;&#12290;&#21482;&#38656;&#30830;&#20445;&#20320;&#27491;&#30830;&#22320;&#35775;&#38382;&#27599;&#20010;&#20803;&#32032;&#21363;&#21487;&#12290;<\/p>\n<p>&#24076;&#26395;&#36825;&#23545;&#20320;&#26377;&#25152;&#24110;&#21161;&#65281;&#22914;&#26524;&#20320;&#26377;&#20219;&#20309;&#30097;&#38382;&#65292;&#35831;&#38543;&#26102;&#25552;&#38382;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312; PHP &#20013;&#36941;&#21382;&#19968;&#20010;&#23545;&#35937;&#21487;&#20197;&#36890;&#36807;&#22810;&#31181;&#26041;&#038;#24335..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[41],"tuisongtax":[],"class_list":["post-630","my1js","type-my1js","status-publish","hentry","my1js2nav-sjjg"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=630"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=630"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=630"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}