{"id":79,"date":"2009-11-28T14:23:00","date_gmt":"2009-11-28T19:23:00","guid":{"rendered":"http:\/\/wukenny.host-ed.net\/?p=79"},"modified":"2009-11-28T14:23:00","modified_gmt":"2009-11-28T19:23:00","slug":"php-tutorial-2","status":"publish","type":"post","link":"http:\/\/kennywu.info\/?p=79","title":{"rendered":"PHP Tutorial -2 (Data type and array)"},"content":{"rendered":"<p><strong>PHP tags<\/strong><br \/>\n<code>&lt;?php         ?&gt;<\/code><br \/>\n<strong>Text Output<\/strong><br \/>\n<code>echo \"something\";<\/code><br \/>\n<strong>Variable <\/strong><br \/>\n<code>echo \"something\"; \/\/$ in front, can not begin with a number, case sensitive<\/code><br \/>\n<strong>Constant<\/strong><br \/>\n<code>define(\"name\", \"value\");<\/code><br \/>\n<strong>Format number<\/strong><br \/>\n<code>echo sprintf(\"%01.2f\", 25);  \/\/25--&gt;25.00<br \/>\necho number_format(25000, 2);  \/\/25000--&gt;25,000.00<\/code><br \/>\n<strong>Single-quoted Vs double-quoted strings <\/strong><br \/>\n<code>$age=12; $result1=\"age\"; $result2='age';  \/\/resut1:<em>12 <\/em>resutl2: <em>$age<\/em><\/code><br \/>\n<strong>Joining string<\/strong>, or concatenation (dot . or .=). To get Hello World!<br \/>\n<code>echo 'Hello'.\" \".'World';<\/code><br \/>\n<strong>Format a date<\/strong> ( August 10, 2006 &#8211;&gt; 2006\/08\/10)<br \/>\n<code>echo date(\"Y\/m\/d\");<\/code><br \/>\n<strong>Array-Create<\/strong>. index starts with 0, use one of the following ways to create.<br \/>\n<code>$pets[0]=\"unicorn\"<\/code><br \/>\n<code>$pets = array(\"dragon\", \"unicorn\", \"tiger\");<\/code><br \/>\n<code>$pets[] =\"dragon\";  $pets[] =\"unicorn\";  $pets[] =\"tiger\";<\/code><br \/>\n<code>$capitals =array(\"CA\" =&gt; \"Sacramento\", \"TX\" =&gt; \"Austin\", \"OR\" =&gt; \"Salem\" );<\/code><br \/>\n<strong>Array-Viewing<\/strong>.<br \/>\n<code>print_r($pets);<\/code><br \/>\n<code>var_dump($pets);<\/code><br \/>\n<strong>Array-Removing<\/strong>.<br \/>\n<code>$pets[2]=\"\";<\/code><br \/>\n<code>unset ($pets[4]);<\/code><br \/>\n<strong>Array-Sorting<\/strong>.<br \/>\n<code>sort(\"pets\");   \/\/To sort an array that has numbers as keys and reassign keys<\/code><br \/>\n<code>asort(\"pets\");   \/\/To sort an array that has strings as keys<\/code><br \/>\n<strong>Array-Getting Values<\/strong>.<br \/>\n<code><strong>list <\/strong>($firstvar, $secondvar)=$pets;<br \/>\n\/\/To get value from an array that <strong>has numbers as keys<\/strong> and put them in variables<br \/>\n<strong>extract<\/strong>(\"pets\");<br \/>\n\/\/To copy all the values from an array into variables named from the corresponding keys. The sample from the book is wrong, since no key was assigned in $shirtInfo<br \/>\n<strong>current<\/strong>($arrayname)   <strong>next<\/strong>($arrayname)  <strong>previous<\/strong>($arrayname)  <strong>end<\/strong>($arrayname)  <strong>reset<\/strong>($arrayname);<br \/>\n\/\/Manually iterate through an array<br \/>\n<strong>foreach<\/strong>($capitals as $state =>$city)<br \/>\n\/\/walks through the array one value at a time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP tags &lt;?php ?&gt; Text Output echo &#8220;something&#8221;; Variable echo &#8220;something&#8221;; \/\/$ in front, can not begin with a number, case sensitive Constant define(&#8220;name&#8221;, &#8220;value&#8221;); Format number echo sprintf(&#8220;%01.2f&#8221;, 25); \/\/25&#8211;&gt;25.00 echo number_format(25000, 2); \/\/25000&#8211;&gt;25,000.00 Single-quoted Vs double-quoted strings $age=12; &hellip; <a href=\"http:\/\/kennywu.info\/?p=79\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[47],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-lamp","tag-php"],"_links":{"self":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":0,"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"wp:attachment":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}