Tag Archive - data

PHP Boolean Type

The boolean data type in PHP is very easy to use (and why should it be difficult, it is either True or it is False).

The basic way to set a boolean value is to use the true and false keyword. Unlike other programming languages, true and false are case insensitive so you can either use true, True, TrUe, or any other variation to get the same effect.

For example:

<?
$yes = true;
$yes2 = True;

$no = false;
$no2 = False;
?>

These are all valid ways to set a variable to true or false.

PHP has some interesing ways of determining if a variable is true or false. Since PHP is a dynamically typed language, nearly any type can be evaulated as true or false. The way you can keep this straight in your head is if the variable’s value is at its default state, it will likely be evaulated as false.

To be more official, here is how PHP evaulates true or false from various values:

  • the boolean FALSE itself
  • the integer 0 (zero)
  • the float 0.0 (zero)
  • the empty string, and the string “0″
  • an array with zero elements
  • an object with zero member variables (PHP 4 only)
  • the special type NULL (including unset variables)
  • SimpleXML objects created from empty tags

Text taken from PHP manual at: http://www.php.net/manual/en/language.types.boolean.php

Flot Tutorial Series: Creating Different Types of Graphs

Today we will discuss how by using Flot, you can display your data in a number of different ways. In Flot you can have a line graph (the default display for Flot), a bar graph, and a point graph.
Continue Reading…

Flot Tutorial Series: Creating A Flot Dataset

The most basic thing that one must know in order to use Flot is to understand how to create a data set. The data set is the actual raw data that Flot uses to construct your chart.

While some other libraries make this difficult to accomplish, Flot actually makes it very simple. In the most basic form, a Flot data set is actually just a multi-dimensional array.

The following is an example of constructing a very basic data set.
var data_set = [[2, 1], [3, 8], [4, 5], [5, 13]];

When this data set is placed on the chart, a line will be created that starts at (2, 1), goes to (3, 8), and so on through the entire data set.

If you want to create a break in your line, you are able to do that as well. Take this for example:
var data_set = [[2, 1], [3, 8], null, [4, 5], [5, 13]];

By placing the null value, we have essentially split the line in half.

Now with a little math, you can create mathematical charts.

var sine_wave = [];
for (var i = 0; i < 14; i += 0.5)
   sine_wave.push([i, Math.sin(i)]);

This data set will create a sine wave.

Now that you have the basic idea how to create a data set, we can continue on to actually creating a chart and placing it on a web page.