<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Beth Granter &#187; training</title>
	<atom:link href="http://bethgranter.com/blog/tag/training/feed/" rel="self" type="application/rss+xml" />
	<link>http://bethgranter.com/blog</link>
	<description>Social media, online communities, interface design, ethics and feminism</description>
	<lastBuildDate>Mon, 21 May 2012 09:09:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>My PHP for beginners notes</title>
		<link>http://bethgranter.com/blog/2008/03/my-php-for-beginners-notes/</link>
		<comments>http://bethgranter.com/blog/2008/03/my-php-for-beginners-notes/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 12:40:48 +0000</pubDate>
		<dc:creator>Beth Granter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[lesson]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[training]]></category>

		<guid isPermaLink="false">http://bethgranter.wordpress.com/?p=96</guid>
		<description><![CDATA[Disclaimer &#8211; there are likely to be mistakes in this, so please point them out!  Here are my notes from my PHP for beginners course, which was excellent, and was run by Highlander.  I know it&#8217;s better to use the PHP manual but it helps me to write ...]]></description>
			<content:encoded><![CDATA[<p>Disclaimer &#8211; there are likely to be mistakes in this, so please point them out!  Here are my notes from my <a href="http://highlander.co.uk/opensource/fasttrack-to-php-mysql-training">PHP for beginners course</a>, which was excellent, and was run by <a href="http://highlander.co.uk">Highlander</a>.  I know it&#8217;s better to use the <a href="http://php.net/">PHP manual</a> but it helps me to write these out so feel free to ignore these!</p>
<h3>DAY 1</h3>
<ul>
<li><font color="#e6240e">boolean</font> = true or false</li>
<li><font color="#e6240e">int</font> = integer</li>
<li><font color="#e6240e">float</font> = fraction</li>
<li><font color="#e6240e">string</font> = text, in quotes</li>
<li><font color="#e6240e">resource</font> = external (not native to PHP) resource</li>
<li><font color="#e6240e">$variablename</font></li>
</ul>
<h4>Associative arrays</h4>
<ul>
<li><font color="#e6240e">$myArray = array (&#8220;keyname1&#8243;=&gt;&#8221;value1&#8243;, &#8220;keyname2&#8243; =&gt;&#8221;value2&#8243;);</font></li>
<li>If no key name is provided, the default is 0, 1, 2&#8230; etc.</li>
<li><font color="#e6240e">[</font>square brackets are used to ACCESS array contents<font color="#e6240e">]</font></li>
<li><font color="#e6240e">(</font>normal brackets are used to SET UP functions and arrays<font color="#e6240e">)</font></li>
</ul>
<h4>HTML</h4>
<p><font color="#e6240e">&lt;pre&gt;<br />
this will print on two<br />
lines, even without a br tag<br />
&lt;/pre&gt;</font></p>
<h4>Examples</h4>
<p><font color="#e6240e">$x = $x + 1;</font><br />
<i>//equals</i><br />
<font color="#e6240e"> x ++;</font></p>
<p><font color="#e6240e">$n = 3;<br />
echo $n * $n- -;</font><br />
<i>// (<b>ignore spaces between minus symbols</b>) equals</i><br />
<font color="#e6240e"> echo $n * ($n- -);</font></p>
<p><i>// two minus symbols after $n means run the line then apply (-1) to $n</i></p>
<p><font color="#e6240e">$n = 3;<br />
echo $n * &#8211; -$n;</font><br />
<i>// equals</i><br />
<font color="#e6240e"> &#8211; -$n;<br />
echo $n*$n;</font></p>
<p><i>// two minus symbols before $n means apply (-1) to $n THEN run whole line.</i></p>
<p><span id="more-96"></span></p>
<p><font color="#e6240e">$a = 10;<br />
$b = $a;                          </font>// <i>SET b to value of $a (10)</i><br />
<font color="#e6240e"> $b = 20;<br />
echo $a;</font>                            //<i>outputs 10</i></p>
<p><font color="#e6240e">$a = 10;<br />
$b = &amp;$a;</font>                <i>  // the &#8216;&amp;&#8217; LINKS $a and $b<br />
</i><font color="#e6240e">$b = 20;<br />
echo $a;                    </font><i>  // outputs 20</i></p>
<p><font color="#e6240e">==</font> means are they the same VALUE?</p>
<p><font color="#e6240e">===</font> means are they the same VALUE AND TYPE (e.g. integer or string)?</p>
<p><font color="#e6240e">$array = array ();</font>        <i> // creates an empty array</i></p>
<p><font color="#e6240e">$array [] = array(&#8216;a&#8217;,'b&#8217;);</font>     <i>// puts array(&#8216;a&#8217;,'b&#8217;) INTO slot 0 of $array[]</i></p>
<p><font color="#e6240e">$a = array(1,2,3);<br />
$b = array(&#8216;a&#8217;=&gt;1,&#8217;b'=&gt;2,&#8217;c'=&gt;3);<br />
$c = array(1,2,3);</font></p>
<p><font color="#e6240e">$a+$b</font>   <i>will produce</i>   <font color="#e6240e">array(1,2,3,1,2,3)</font></p>
<p><font color="#e6240e">$a+$c</font>   <i>will produce</i>   <font color="#e6240e">array(1,2,3)</font>     <i>//as values and keys are the same</i></p>
<ul>
<li><font color="#e6240e">isset</font> checks if a key has ANY value</li>
<li><font color="#e6240e">array_key_exists</font> checks if a key <i>exists</i></li>
<li><font color="#e6240e">in_array</font> checks is a CERTAIN VALUE exists</li>
<li><font color="#e6240e">array_flip</font> swaps keys for their values</li>
<li><font color="#e6240e">array_reverse</font> reverses ORDER of values &#8211; keys remain in place</li>
</ul>
<p>e.g. <font color="#e6240e"><br />
$a = array(&#8216;a&#8217;=NULL);<br />
echo isset($a['a'])       </font><i>//will FAIL because NULL means no value</i><br />
<font color="#e6240e">echo array_key_exists(&#8216;a&#8217;,$a)   </font><i>//will PASS (because &#8216;a&#8217; exists)</i><br />
<font color="#e6240e">echo in_array(2,$a)</font>     <i>//will FAIL because there is no &#8217;2&#8242; value in $a</i></p>
<h3>DAY 2</h3>
<p><font color="#e6240e">sort($array); </font><i><br />
//will destroy keys and put values in alphabetical order, assigned to default numerical keys, i.e. 0,1,2&#8230;</i></p>
<p><font color="#e6240e">asort($array); </font><br />
<i>//keeps keys and arranges in order of values alphabetically</i></p>
<p>Ascending order (A-&gt;Z) is default.  Descending order uses <font color="#e6240e">rsort() </font>and <font color="#e6240e">arsort()</font>.</p>
<p>sort <i>would do 1,20,11,2,3 etc.</i><br />
<font color="#e6240e">natsort</font> <i>realises that 10 is bigger than 9, so does 1,2,3&#8230;8,9,10,11&#8230;.</i></p>
<p><font color="#e6240e">ksort</font> <i>//puts in alphabetical order by KEY</i><br />
<font color="#e6240e">krsort</font> <i>//orders alphabetically in descending order by key</i></p>
<p><font color="#e6240e">shuffle</font> //<i>puts values in random order (keys destroyed and reassigned as 0,1,2&#8230;)</i></p>
<p><font color="#e6240e">array_keys()</font> //<i>puts KEYS into their own array, in the order they are already in (doesn&#8217;t sort alphabetically).</i></p>
<p><font color="#e6240e">array_push($stack,&#8217;foo&#8217;,'bar&#8217;);</font>         <i>//adds </i>foo<i>, then </i>bar<i>, to array </i>$stack<i>. </i></p>
<p><font color="#e6240e">array_diff($a,$b)</font> <i>//produces any VALUES in $a which are NOT in $b.  Keys are not compared, but are KEPT. </i></p>
<p><font color="#e6240e">array_intersect($a,$b)</font>  <i>//returns &#8216;duplicate&#8217; values (that are found in $a AND $b), irrelevant of key, but key from $a is kept.  If two &#8216;x&#8217; values are found in $a and one is found in $b, <b>both</b> values from $a are returned.</i></p>
<p>If using $something in a string, use double quotes.  Only use single quotes for plain text to be output literally (not processed).</p>
<p><font color="#e6240e">PHP_EOL  </font>  <i>//end of line</i></p>
<p><font color="#e6240e">error_reporting(0); </font> <i>//returns all errors.  Other numbers limit error messages to certain ones.</i></p>
<h4>Comparing strings</h4>
<p><font color="#e6240e">if(strcmp($str,&#8221;hello&#8221;)===0);</font></p>
<p><i></i></p>
<p>In a form, if you set the name of multiple items to<font color="#e6240e"> something[]</font>, this tells PHP they are all in the same array.</p>
<p><font color="#e6240e">setcookie(&#8220;filename_of_cookie&#8221;,&#8221;content_of_cookie&#8221;); </font>  <i>//creates cookie</i></p>
<p><font color="#e6240e">setcookie(&#8220;filename_of_cookie&#8221;,false);  </font>     <i>//deletes cookie</i></p>
<h3>DAY 3</h3>
<p><font color="#e6240e">rand(0,100);</font>  <i>//gives a random number between 0 and 100</i></p>
<p><font color="#e6240e">mysql_fetch_row </font>   <i>//automatically repeats through all rows</i></p>
<p><font color="#e6240e">mysql_connect(host,username,password);</font></p>
<p><font color="#e6240e">mysql_list_dbs</font></p>
<p>Applications used: database browser &#8211; Navicat.  mySQL Administrator.  XAMPP Control Panel.</p>
<p>On navicat, where it shows a lock on a folder, it&#8217;s THAT ONE that has some privileges ALLOWED.  No lock means NO privileges at all for that user have been given.</p>
<p><font color="#e6240e">$_GET</font> gets info from the URL.</p>
<p><font color="#e6240e">e</font><font color="#e6240e">cho &#8220;&lt;form name=\&#8221;search Form\&#8221;action=\&#8221;search.php\&#8221;method=\&#8221;get\&#8221;&gt;&#8221;;</font></p>
<p><i>// The &#8216;get&#8217; here, puts whatever is input, into the URL.</i></p>
<p><font color="#e6240e">echo &#8220;&lt;select name=\&#8221;mysearch\&#8221;&gt;&#8221;;</font><br />
<i>//mysearch is put into ULR e.g. http://www.something.com?mysearch=input</i></p>
]]></content:encoded>
			<wfw:commentRss>http://bethgranter.com/blog/2008/03/my-php-for-beginners-notes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

