{"id":2907,"date":"2020-03-09T16:23:33","date_gmt":"2020-03-09T23:23:33","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2907"},"modified":"2020-03-09T16:23:33","modified_gmt":"2020-03-09T23:23:33","slug":"updating-sites-php-notes","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2907","title":{"rendered":"Updating sites\u2014PHP Notes"},"content":{"rendered":"<p>As I mentioned in the previous posts, I\u2019m using <a href='https:\/\/www.w3schools.com\/'>W3Schools<\/a> to review HTML, CSS, and PHP  in order to create some exercises. Here are a few things that I didn\u2019t know about PHP or want to remind myself about.<\/p>\n<p>When sending users to specific pages I often use numbers to indicate which page they should go to. Spambots will frequently put in random junk so I do some tests before I process the request. PHP has some odd behaviour with some of the functions. For example,<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n\/\/ Invalid calculation will return a NaN value\n$x = acos(8);\necho is_nan($x);&nbsp;&nbsp;&nbsp;&nbsp; --&gt; 1\necho var_dump($x);&nbsp;&nbsp; --&gt; float(NAN)\necho is_null($x);&nbsp;&nbsp;&nbsp;&nbsp;--&gt; expect 0 but get a blank line, so only works on numbers\u2014not NAN\necho is_finite($x);&nbsp;&nbsp;--&gt; blank line, so only works on numbers\u2014not NAN\n\necho is_finite(&quot;Hello&quot;);&nbsp;&nbsp;&nbsp;&nbsp; --&gt; Warning: is_finite() expects parameter to be a float\necho is_finite(10);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; 1\necho is_infinite(10);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; expect 0 but get a blank line\necho is_infinite(10e1111);&nbsp;&nbsp; --&gt; 1\n\n\/\/ $hello not defined\necho var_dump($hello);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt; NULL\necho is_nan($hello);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt; blank line\necho is_null($hello);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; 1\necho is_finite($hello);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; 1\necho is_infinite($hello);&nbsp;&nbsp;&nbsp;&nbsp;--&gt; expect 0 but get a blank line\necho is_int($hello);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt; expect 0 but get a blank line\n\nvar_dump(is_numeric($hello)); --&gt; bool(true) \nis_numeric($hello);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt; expect 0 but get a blank line\n<\/code><\/pre><\/p>\n<p>I never gave constants much thought when developing web pages, but i\u2019m thinking that they might come in handy when making interactive games. If I access the database and grab a bunch of data that will be displayed but won\u2019t change, it should go into a constant array which is then accessible to any function on the page. Note that both constant arrays and variables are referenced by their name without a $ before the name.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\ndefine(&quot;cars&quot;, [\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;Alfa Romeo&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;BMW&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;Toyota&quot;\n]);\necho cars[0];&nbsp;&nbsp;--&gt; Alfa Romeo\n\nfunction arrayDisplay() {\n&nbsp;&nbsp;foreach (cars as $value) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;$value &quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\narrayDisplay();&nbsp;&nbsp;--&gt; Alfa Romeo BMW Toyota\n<\/code><\/pre><\/p>\n<p>If you use a variable array, the array isn\u2019t available to functions.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n$cars = array(\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;Alfa Romeo&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;BMW&quot;,\n&nbsp;&nbsp;&nbsp;&nbsp;&quot;Toyota&quot;\n);\nvar_dump($cars);&nbsp;&nbsp;--&gt;&nbsp;&nbsp;array(3) { [0]=&gt; string(10) &quot;Alfa Romeo&quot; [1]=&gt; string(3) &quot;BMW&quot; [2]=&gt; string(6) &quot;Toyota&quot; }\n\nfunction arrayDisplay() {\n&nbsp;&nbsp;foreach ($cars as $value) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;$value &quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\narrayDisplay(); -- &gt; Warning: Invalid argument supplied for foreach() \u2026 \n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I mentioned in the previous posts, I\u2019m using W3Schools to review HTML, CSS, and PHP in order to create some exercises. Here are a few things that I didn\u2019t know about PHP or want to remind myself about. When sending users to specific pages I often use numbers to indicate which page they should &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2907\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Updating sites\u2014PHP Notes<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-2907","post","type-post","status-publish","format-standard","hentry","category-html-and-css"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2907"}],"version-history":[{"count":7,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2907\/revisions"}],"predecessor-version":[{"id":2914,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2907\/revisions\/2914"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}