You are here: Daniel Dumas »

Category : PHP

PHP Operators: The === Operator

PHP’s === Operator enables you to compare or test variables for both equality and type. Refer below for example.

<?php
//define variables..
$str = '9';
$int = 9;

//Returns true since both variable contains the same value..
$res = ($str==$int);

//Returns false since the two variables are not of the same type..
$res = ($str===$int);
?>

PHP Operators : Using Comparison Operators

To compare php variables to determine whether they are the same or different.. you can use PHP Comparison Operators. See below for a list of examples..

I. Define the Variables

<?php
$num1 = 9;
$num2 = 9;
$num3 = 22;
?>

A. The Less Than Operator

<?php
//Returns true if variable in the left side is less than the right..
$res = ($num1 < $num3);
//returns true..
?>

Keep Reading…

PHP Operators: Using String Concatenation Operator

You can concatenate or add strings together using the PHP string concatenation operator represented by the period sign ( . ). refer to the examples below.

<?php
// intialize variables
$username = "daniel";
$domain = "danieldumas.com";

// the variable string $username and $domain can be combine using the concatenation operator
$email_address = $username . '@'. $domain;

//the variable $email_address now contains the value "daniel@danieldumas.com"

?>

You can also concatenate simultaneously. . Keep Reading…

PHP Operators : Using Arithmetic Operators

Using Arithmetic Operators in PHP you can perform mathematical operations on PHP variables. refer to the example below.

Using PHP Arithmetic Operator

//define variables
<?php

$num1 = 50;
$num2 = 30;

//Addition
$sum = $num1 + $num2;

//Subtraction
$difference = $num1 - $num2;

//Multiplication
$product = $num1*$num2;

//Division
$quotient = $num1 / $num2;

//Modulus
$remainder = $num1 % $num2;

?>

you may also use the shorthand using the PHP Assignment Operator and Arithmetic Operator together. Keep Reading…

PHP Operators

PHP Operators are very important, if PHP variables is the building blocks of PHP programming PHP Operators is the tool that lets you do something useful with variables. php comes with many useful operators such as Assignment Operator, Arithmetic Operator, String Operator, Comparison Operator and Logical Operator. Keep Reading…

Detecting the data type of a PHP variable

Detecting the datatype of a specific PHP variable can be done by using PHP gettype() function. refer below for example.

<?php

//define variables
$on = true;
$age = 20;
$name = "daniel";
$price = 99.99;

//Returns Boolean
echo gettype($on);

//Returns String
echo gettype($name);

//Returns Integer
echo gettype($age);

//Returns Double
echo gettype($price);

?>

Keep Reading…

PHP and MySQL Basics: Saving form input in PHP variables

form can add interactivity to your site, it enables you to get information or comments from your visitors. saving a value from a form input to a php variable is very easy. refer to the example below.

Example 1: Processing forms in the same php file

Copy and Paste the code below to your text editor and save it as form.php, then run it on your localhost Keep Reading…

Fix wordpress fatal error allowed memory size exhausted

Fatal error: Allowed memory size of …… bytes exhausted (tried to allocate …. bytes) in home/of/some/thing/fishy.php :)

Wordpress Fatal Error allowed memory size exhaustedI experienced this weird Wordpress or rather PHP error last night when trying to view my blog when i got home, at first i thought that there was a technical problem at my server so i waited, then i waited and waited and waited again for almost 7 hours then i cant wait no more i want to blogggg… so i contact my hosting provider and they told me that there is nothing wrong with the server nahhh WTF! i told to my self. . :) Keep Reading…

PHP and MySQL Basics: Assigning and Using Variables

Assigning a value to PHP variable is very easy, you can use the assignment operator ( = ) to store values into a php variable. refer below for example.

<html>
<head>
<title>Assigning Values to PHP Variable</title>
</head>
<body>
<?php
//this is how you assign a value to a php variable
$age = 20;
//To use the variable $age, simply call its name and PHP will substitute its value at runtime.
//this is how you use a php variable
echo "I am now $age years old";
?>
</body>
</html>

copy and paste the code above to your text editor and save it as variable.php then run it on your localhost.

you should get this output.. Keep Reading…

PHP and MySQL Basics: Variables

Variables are the building blocks of any programming language. in PHP variables are very important, it used to store numeric or non-numeric datas. PHP supports different types of variable types (Booleans, Integers, Floating point numbers, Strings, Arrays, Objects, resources and nulls.

PHP VARIABLE NAMING RULES:

  1. PHP variables starts with a $ sign : example. $daniel
  2. $ sign is followed by a letter or an underscore. thus $123 is not a valid PHP variable. Keep Reading…