Page 38 - Open Soource Technologies 304.indd
P. 38
Web Technologies-I
Notes You just need to make sure that your termination string does not occur anywhere in the content
being delimited.
2.2.6 Boolean
A Boolean value assesses the truth value of something. Booleans only have two values, true and
false. These two values are represented by the keyword literals of the same name. All conditionals
return a true/false boolean value based on the condition being tested.
If a conditional is converted to a different data type, then true equates to one (1) and false equates
to zero (0). The conversion in the other directions is a little more complex. If testing for the truth
value of a non-boolean value, any of the following values will equate to false:
• The keyword literal false.
• The integer 0.
• The floating-point number 0.0.
• The empty string (“”). Note that is not a space, but a string with nothing in it.
• The string “0” (zero).
• An object with no values or methods.
• The null value.
All other values are true, including all resource values.
2.2.7 Compound Data Types
Arrays
An array is a variable that holds a group of values. Arrays are usually meant to store a collection
of related data elements, although this is not a necessity. You access the individual elements by
referring to their index position within the array. The position is either specificied numerically or
by name.
An array with a numeric index is commonly called an indexed array while one that has named
positions is called an associative array. In PHP, all arrays are associative, but you can still use a
numeric index to access them. Indexed arrays start at position zero, not at position one, so your
first array element has an index of 0, and the highest position in the array is one less than the
number of elements in the array.
Referencing array elements is done with the following notation:
$arrayName[index];
You assign a value to an array position by specifying which array element you want to assign a
value to:
$listing[0] = “first item”;
$listing[1] = “second item”;
$listing[2] = “third item”;
An individual array element can be of any type, including another array.
If you want to find out if a variable contains an array you can use the is_array() function.
We deal extensively with arrays in their own section. If you have not gotten to it yet, beware of
the fact that there are some counterintuitive elements in how PHP deals with arrays. For example,
given the following statements, what is the value of $arName[1]?
32 LOVELY PROFESSIONAL UNIVERSITY