\documentclass[10pt,a4paper]{article}

% Packages
\usepackage{fancyhdr}           % For header and footer
\usepackage{multicol}           % Allows multicols in tables
\usepackage{tabularx}           % Intelligent column widths
\usepackage{tabulary}           % Used in header and footer
\usepackage{hhline}             % Border under tables
\usepackage{graphicx}           % For images
\usepackage{xcolor}             % For hex colours
%\usepackage[utf8x]{inputenc}    % For unicode character support
\usepackage[T1]{fontenc}        % Without this we get weird character replacements
\usepackage{colortbl}           % For coloured tables
\usepackage{setspace}           % For line height
\usepackage{lastpage}           % Needed for total page number
\usepackage{seqsplit}           % Splits long words.
%\usepackage{opensans}          % Can't make this work so far. Shame. Would be lovely.
\usepackage[normalem]{ulem}     % For underlining links
% Most of the following are not required for the majority
% of cheat sheets but are needed for some symbol support.
\usepackage{amsmath}            % Symbols
\usepackage{MnSymbol}           % Symbols
\usepackage{wasysym}            % Symbols
%\usepackage[english,german,french,spanish,italian]{babel}              % Languages

% Document Info
\author{williamdavies}
\pdfinfo{
  /Title (php-fundamentals.pdf)
  /Creator (Cheatography)
  /Author (williamdavies)
  /Subject (PHP fundamentals Cheat Sheet)
}

% Lengths and widths
\addtolength{\textwidth}{6cm}
\addtolength{\textheight}{-1cm}
\addtolength{\hoffset}{-3cm}
\addtolength{\voffset}{-2cm}
\setlength{\tabcolsep}{0.2cm} % Space between columns
\setlength{\headsep}{-12pt} % Reduce space between header and content
\setlength{\headheight}{85pt} % If less, LaTeX automatically increases it
\renewcommand{\footrulewidth}{0pt} % Remove footer line
\renewcommand{\headrulewidth}{0pt} % Remove header line
\renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit
% This two commands together give roughly
% the right line height in the tables
\renewcommand{\arraystretch}{1.3}
\onehalfspacing

% Commands
\newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour
\newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols
\newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns
\newcommand{\tn}{\tabularnewline} % Required as custom column type in use

% Font and Colours
\definecolor{HeadBackground}{HTML}{333333}
\definecolor{FootBackground}{HTML}{666666}
\definecolor{TextColor}{HTML}{333333}
\definecolor{DarkBackground}{HTML}{054FA3}
\definecolor{LightBackground}{HTML}{EFF4F9}
\renewcommand{\familydefault}{\sfdefault}
\color{TextColor}

% Header and Footer
\pagestyle{fancy}
\fancyhead{} % Set header to blank
\fancyfoot{} % Set footer to blank
\fancyhead[L]{
\noindent
\begin{multicols}{3}
\begin{tabulary}{5.8cm}{C}
    \SetRowColor{DarkBackground}
    \vspace{-7pt}
    {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent
        \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}}
    }
\end{tabulary}
\columnbreak
\begin{tabulary}{11cm}{L}
    \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{PHP fundamentals Cheat Sheet}}}} \\
    \normalsize{by \textcolor{DarkBackground}{williamdavies} via \textcolor{DarkBackground}{\uline{cheatography.com/20136/cs/2972/}}}
\end{tabulary}
\end{multicols}}

\fancyfoot[L]{ \footnotesize
\noindent
\begin{multicols}{3}
\begin{tabulary}{5.8cm}{LL}
  \SetRowColor{FootBackground}
  \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}}  \\
  \vspace{-2pt}williamdavies \\
  \uline{cheatography.com/williamdavies} \\
  \end{tabulary}
\vfill
\columnbreak
\begin{tabulary}{5.8cm}{L}
  \SetRowColor{FootBackground}
  \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}}  \\
   \vspace{-2pt}Not Yet Published.\\
   Updated 13th May, 2016.\\
   Page {\thepage} of \pageref{LastPage}.
\end{tabulary}
\vfill
\columnbreak
\begin{tabulary}{5.8cm}{L}
  \SetRowColor{FootBackground}
  \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}}  \\
  \SetRowColor{white}
  \vspace{-5pt}
  %\includegraphics[width=48px,height=48px]{dave.jpeg}
  Measure your website readability!\\
  www.readability-score.com
\end{tabulary}
\end{multicols}}




\begin{document}
\raggedright
\raggedcolumns

% Set font size to small. Switch to any value
% from this page to resize cheat sheet text:
% www.emerson.emory.edu/services/latex/latex_169.html
\footnotesize % Small font.

\begin{multicols*}{3}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Arrays}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{{\bf{Normal array}} \newline \$myGadgets = array('iMac', 'iPad', 'iPhone'); \newline  \newline {\bf{Shorthand array}} \newline \$myGadgets = {[}'iMac', 'iPad', 'iPhone'{]}; \newline  \newline {\bf{Associative array}} \newline \$myGadgets = array('computer'=\textgreater{}'iMac', 'tablet'=\textgreater{}'iPad', 'phone'=\textgreater{}'iPhone'); \newline  \newline echo \$myGadgets{[}'phone'{]}; {\emph{(will output iPhone)}} \newline  \newline {\bf{Append to an array}} \newline \$myGadgets{[}{]} = 'sounddock'; \newline  \newline {\bf{Examine contents and structure of array}} \newline print\_r(\$myGadgets); \newline  \newline {\bf{Output a value from an array}} \newline echo \$myGadgets{[}1{]}; \newline {\emph{(Will output 'iPad')}} \newline  \newline {\bf{Convert entire array to string}} \newline echo implode(', ', \$myGadgets);  \newline {\emph{(First argument is how you would like to seperate each element)}}} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{Arrays are a good way to store several related items of data such personal details (name, address, DOB)}  \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Variables}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{{\bf{Variables can store strings and numbers}} \newline \$txt = "Hello world!"; \newline \$x = 5; \newline \$y = 10.5; \newline  \newline {\bf{Variables can be outputted in the follwing way}} \newline \$txt = "Will"; \newline echo "My name is " . \$txt . "!"; \newline  \newline {\bf{Use a global variable inside a function}} \newline \$x = 5; \newline \$y = 10; \newline  \newline function myTest() \{ \newline     global \$x, \$y; \newline     \$y = \$x + \$y; \newline \}} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Loops}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{{\bf{for loop}} \newline for (\$x = 5; \$x \textless{}= 100; \$x++) \{ \newline    echo "The number is " . \$x; \newline \} \newline {\emph{(The first parameter is the initial value of the variable, the second value controls how many times the loop will execute)}} \newline  \newline {\bf{foreach loop}} \newline \$myGadgets= array('iMac', 'iPad', 'iPhone'); \newline foreach (\$myGadgets AS \$myGadget)\{ \newline echo '\textless{}li\textgreater{}' . \$myGadget . '\textless{}/li\textgreater{}'; \newline \} \newline {\emph{(Outputs each element of the array as a list item)}} \newline  \newline {\bf{while loop}} \newline \$x = 1; \newline while(x \textless{}= 5)\{ \newline echo "Hello World"; \newline x++; \newline \} \newline {\emph{(Loop continues until condition is no longer true)}} \newline  \newline {\emph{*do while loop}} \newline \$x = 1;  \newline do \{ \newline     echo "Hello World"; \newline     \$x++; \newline \} while (\$x \textless{}= 5); \newline {\emph{(Identical to a while loop except the code is executed once regardless of if the condition is met)}}} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{{\bf{while}} - loops through a block of code as long as the specified condition is true \newline  \newline {\bf{do while}} - loops through a block of code once, and then repeats the loop as long as the specified condition is true \newline  \newline {\bf{for}} - loops through a block of code a specified number of times \newline  \newline {\bf{foreach}} - loops through a block of code for each element in an array}  \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{String functions}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{\seqsplit{explode(string\_separator}, \$str, limit); \newline  \newline implode(string\_separator, array); \newline  \newline str\_replace(find, replace, string, count); \newline  \newline str\_word\_count(string, return, char); \newline  \newline strlen(\$str); \newline  \newline strlower(\$str); \newline  \newline strtoupper(\$str); \newline  \newline trim(\$str, chars); \newline  \newline wordwrap(\$str, width, break, cut); \newline  \newline substr(\$str, start, length)} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{Not all parameters required.}  \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Miscellaneous}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{{\bf{Escaping characters}} \newline  \newline When using doubles quotes for example "hello world" you can escape characters with a backslash \textbackslash{} \newline  \newline break; (stops loop) \newline exit; (stops php script)} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Date and Time}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{h : 12 hr format \newline H : 24 hr format \newline i : Minutes \newline s : Seconds \newline u : Microseconds \newline a : Lowercase am or pm \newline l : Full text for the day \newline F : Full text for the month \newline j : Day of the month \newline S : Suffix for the day \newline Y : 4 digit y \newline  \newline echo date('h:i:s');} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}

\begin{tabularx}{5.377cm}{X}
\SetRowColor{DarkBackground}
\mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Post}}  \tn
\SetRowColor{LightBackground}
\mymulticolumn{1}{x{5.377cm}}{\$firstName = \$\_POST{[}'fname'{]};} \tn 
\hhline{>{\arrayrulecolor{DarkBackground}}-}
\end{tabularx}
\par\addvspace{1.3em}


% That's all folks
\end{multicols*}

\end{document}