{"id":37,"date":"2008-11-13T19:02:27","date_gmt":"2008-11-13T19:02:27","guid":{"rendered":"http:\/\/dev001.dl\/yan\/wdp\/?p=37"},"modified":"2026-01-20T05:06:49","modified_gmt":"2026-01-20T05:06:49","slug":"arrays-in-php","status":"publish","type":"post","link":"http:\/\/www.lalife.net\/?p=37","title":{"rendered":"Arrays in PHP"},"content":{"rendered":"<p><strong>To define an Array<\/strong><\/p>\n<div style=\"background-color:#ffffe0\">$prod = array();<\/div>\n<div style=\"background-color:#ffffe0\">$prod = array(&#8220;a&#8221;,&#8221;b&#8221;,&#8221;c&#8221;);<\/div>\n<div style=\"background-color:#ffffe0\">\n<p>$prod = array(<br \/>\n&#8220;prod1&#8221; =&gt; array(&#8220;id&#8221;=&gt;&#8221;prod001&#8243;,&#8221;date&#8221; =&gt;\u00a0&#8220;111208&#8221;, &#8220;name&#8221;=&gt;&#8221;aaa&#8221;);<br \/>\n&#8220;prod2&#8221; =&gt; array(&#8220;id&#8221;=&gt;&#8221;prod002&#8243;,&#8221;date&#8221; =&gt;\u00a0&#8220;111108&#8221;, &#8220;name&#8221;=&gt;&#8221;bbb&#8221;);<br \/>\n&#8220;prod3 =&gt; array(&#8220;id&#8221;=&gt;&#8221;prod003&#8243;,&#8221;date&#8221; =&gt;\u00a0&#8220;111008&#8221;, &#8220;name&#8221;=&gt;&#8221;ccc&#8221;);<br \/>\n);<\/p><\/div>\n<div style=\"background-color:#ffffe0\">$data=array();<br \/>\n$data[&#8216;id&#8217;] = 1;<br \/>\n$data[&#8216;name&#8217;] = &#8216;John&#8217;;<\/div>\n<p><strong>To read values out<\/strong><\/p>\n<div style=\"background-color:#ffffe0\">foreach($SITE as $key1 =&gt; $val1){<\/p>\n<p>foreach($sval1 as $key2 =&gt; $val2){<\/p>\n<p>if($key2==&#8221;id&#8221;)\u00a0echo &#8220;ID: $val2[0]\\n&#8221;;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>foreach($data as $value){<\/p>\n<p>echo $value.&#8221;\\n&#8221;;<\/p>\n<p>}<\/p><\/div>\n<p><strong>Push elements into Array<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To define an Array $prod = array(); $prod = array(&#8220;a&#8221;,&#8221;b&#8221;,&#8221;c&#8221;); $prod = array( &#8220;prod1&#8221; =&gt; array(&#8220;id&#8221;=&gt;&#8221;prod001&#8243;,&#8221;date&#8221; =&gt;\u00a0&#8220;111208&#8221;, &#8220;name&#8221;=&gt;&#8221;aaa&#8221;); &#8220;prod2&#8221; =&gt; array(&#8220;id&#8221;=&gt;&#8221;prod002&#8243;,&#8221;date&#8221; =&gt;\u00a0&#8220;111108&#8221;, &#8220;name&#8221;=&gt;&#8221;bbb&#8221;); &#8220;prod3 =&gt; array(&#8220;id&#8221;=&gt;&#8221;prod003&#8243;,&#8221;date&#8221; =&gt;\u00a0&#8220;111008&#8221;, &#8220;name&#8221;=&gt;&#8221;ccc&#8221;); ); $data=array(); $data[&#8216;id&#8217;] = 1; $data[&#8216;name&#8217;] = &#8216;John&#8217;; To read values out &hellip; <a href=\"http:\/\/www.lalife.net\/?p=37\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37"}],"version-history":[{"count":1,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":1971,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions\/1971"}],"wp:attachment":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}