To become more familiar with each other
https://w3techs.com/technologies/history_overview/programming_language
https://toggl.com/programming-princess
https://stackoverflow.blog/2017/10/31/disliked-programming-languages/
http://blog.jasonwelter.com/wp-content/uploads/2011/05/learning_to_code.jpg
$condition = true;
$y = "Yey!";
$n = "Ney!";
$result;
//Normal if
if($condition){
$result = $y;
} else {
$result = $n;
}
//Ternary or "inline if"
$result = $condition ? $y : $n;
$result = FALSE ? "a" : FALSE ? "b" : "c";
$result = TRUE ? "a" : FALSE ? "b" : "c";
$result = TRUE ? "a" : FALSE ? "b" : "c";
$result = (TRUE ? "a" : FALSE) ? "b" : "c";
$result = "a" ? "b" : "c";
$result = TRUE ? "a" : (FALSE ? "b" : "c"); // "a"
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)
get_class(); gettype();
base64_encode(); urlencode();
htmlentities(); html_entity_decode();
stream_copy_to_stream(); strtolower();
bin2hex(); deg2rad();
void usleep ( int $micro_seconds )
mixed microtime ([ bool $get_as_float = false ] )
$string = "ThisIsAString";
$array = [];
parse_str($string, $array);
Hint: The array argument is optional
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first; // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
parse_str($str, $output);
echo $output['first']; // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz
While PHP meanwhile supports the OOP principle, this wasn't always the case. That's why all APIs are present as procedural and object-oriented version. Mixing these versions up can lead to..
Because PHP is dynamically typed, code can get messy quite fast when not following some code styles, rules, patterns and conventions. That's also one important thing to know about PHP
echo '<h1>New Users</h1>';
$sql = "SELECT * FROM users ORDER BY date_registered";
$result = mysql_query($sql) or die(mysql_error()); echo '<table class="my-table-class">';
while($row = mysql_fetch_assoc($result)){
echo '<tr><td>' . $row['username'] . '</td><td>' . $row['date_registered'] . '</td></tr>';
}
echo '</table>';
function random_custom_function($var){
$var = $var + 1;
return '<span style="font-weight:bold;">' . $var . '</span>';
}
$sql = "SELECT * FROM table WHERE column = 'test'";
$result = mysql_query($sql) or die(mysql_error());
echo '<div id="test">'; $i = 0;
while($row = mysql_fetch_assoc($result)){
if($row['type'] == 3){
echo '<div style="margin-bottom:20px;">' . random_custom_function($row['val']) . '</div>';
$i++;
} else {
echo '<div style="margin-bottom:20px;">' . $row['val'] . '</div>';
}
}
if($i == 0){
echo 'Found none!';
}
http://www.zend.com/en/resources/php7_infographic
Source: https://upload.wikimedia.org/wikipedia/commons/2/21/Mandel_zoom_00_mandelbrot_set.jpg
Source: https://xkcd.com/303/
Source: http://www.zend.com/en/resources/php7_infographic
Source: http://getcomposer.org/
$nameErr = $emailErr = $name = $email = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
}
echo json_encode(["name" => $name, "email" => $email]);
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
class BasicValidationRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
"name" => "string|required|min:3|max:255",
"email" => "string|required|email|min:3|max:255",
];
}
}
class FormController extends Controller
{
public function results(Request $request)
{
echo json_encode($request->all());
}
}