<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tina Morlock</title>
    <description>The latest articles on DEV Community by Tina Morlock (@tinamorlock).</description>
    <link>https://dev.to/tinamorlock</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2254349%2F45a3ad7b-e807-4412-b270-5e1f352631b2.jpeg</url>
      <title>DEV Community: Tina Morlock</title>
      <link>https://dev.to/tinamorlock</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tinamorlock"/>
    <language>en</language>
    <item>
      <title>PHP Cheat Sheet for Beginners</title>
      <dc:creator>Tina Morlock</dc:creator>
      <pubDate>Thu, 15 May 2025 16:58:57 +0000</pubDate>
      <link>https://dev.to/tinamorlock/php-cheat-sheet-for-beginners-4ji2</link>
      <guid>https://dev.to/tinamorlock/php-cheat-sheet-for-beginners-4ji2</guid>
      <description>&lt;p&gt;&lt;em&gt;Note: I am primarily using this as a study tool as I'm upskilling my foundational knowledge. With this in mind, this document is ongoing, and I'll likely be updating it weekly.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opening and closing tags:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php ?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: omitting the closing tag at the end of a file can be beneficial so you don't have any unwanted white space at the end of the file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Printing:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo 'This prints to the screen.';
&amp;lt;?= 'This works too.'; ?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Commenting:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# This is a one-line comment in PHP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multi-line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* This is a multi-
line comment in PHP */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Checking variable type:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var_dump($var_name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Comparing Floats:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Note: Comparing floats in PHP is tricky because of precision. The following is a workaround for that limitation.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$a = 1.23456789;
$b = 1.23456780;
$epsilon = 0.00001;

if (abs($a - $b) &amp;lt; $epsilon) {
    echo "true";
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;String Definitions:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'this is a string'

"this is a string"

&amp;lt;&amp;lt;&amp;lt;END
   this
        is also
               a string
END

&amp;lt;&amp;lt;&amp;lt;'EOD'
This is an example of
another type of string
you can use in PHP.
EOD

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;String Interpolation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$juice = "apple";

echo "He drank some $juice juice." . PHP_EOL;

?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo 'this line prints a {$var}';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;String concatenation uses a . rather than a + in PHP.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I used PHP's documentation as the source of my information here. Some of the code will be similar or identical.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
