Enter Keyword Hear for Search This Blog

Monday, 2 April 2018

Variable Types

Variable Types
Variable Types
Variable Types



Integers

An integer is any numeric value that does not have a decimal point, such as the following:

• 5 (five) 
• –5 (negative five) 
• 0123 (preceded by a zero; octal representation of decimal number 83) 
• 0x12 (preceded by 0x; hexadecimal representation of decimal number 18)

Floating-Point Numbers

A floating-point number (commonly referred to simply as a float or double, which, in PHP, are exactly the same thing) is a numeric value with a decimal point.

The following are all floating-point values:

• 5.5 
• .055e2 (scientific notation for .055 times 10 to the second power, which is 5.5) 
• 19.99

The second example is a float represented in scientific notation. The e, as is often the case on graphing calculators, means “times 10 to the”. It is followed by whatever power 10 should be raised to in order to put the decimal wherever you want it. Thus, .055e2 is the same as .055 times 100, which is 5.5.

Arrays

ARRAY INDEXING

The following example demonstrates the construction of an array containing

five names, then printing each name on a separate line:

<?php
/* ch02ex03.php – demonstration of arrays */
$namesArray = Array(‘Joe’, ‘Bob’, ‘Sarah’, ‘Bill’, ‘Suzy’);
echo “$namesArray[0]<br>”;
echo “$namesArray[1]<br>”;
echo “$namesArray[2]<br>”;
echo “$namesArray[3]<br>”;
echo “$namesArray[4]<br>”;

?>

NOTE : The <br> tags are given here to separate each element of the array on a separate line.

The following example demonstrates the use of empty brackets after an
array to add new elements and also explicitly defines a certain element in

an array:

$namesArray = Array(‘Joe’, ‘Bob’, ‘Sarah’, ‘Bill’, ‘Suzy’);
$namesArray[] = ‘Rachel’; // adds ‘Rachel’ as $namesArray[5]

$namesArray[3] = ‘John’; // replaces ‘Bill’ with ‘John’


Strings

Single-quoted strings are always interpreted just as they are. For example, to use “My variable is called $myVariable” as a string, use the statement found in the following example:

<?php
/* ch02ex04.php – shows use of single-quoted strings */
echo ‘My variable is called $myVariable’;

?>

The output from this example is

My variable is called $myVariable


As you may have noticed from the echo statements found earlier in this
chapter, double-quoted strings are interpreted so that variables are
expanded before they are actually stored as a value. Consider the following

example:

<?php

/* ch02ex05.php – shows use of double-quoted strings */
// Do single-quote assignment and output result
$myVariable = ‘My variable is called $myVariable’;
echo $myVariable;
// Move to new line
echo ‘<br>’;
// Do double-quote assignment and output result
$myVariable = “My variable is called $myVariable”;echo $myVariable;

?>

The output from this example is :

My variable is called $myVariable

My variable is called My variable is called $myVariable

CHARACTER ESCAPING

The following example uses character escaping to include $strSmall’s name
and its contents surrounded by quotes inside the string $strBig:

<?php
/* ch02ex06.php – demonstrates character escaping */
$strSmall = “John Smith”;

$strBig = “The name stored in \$strSmall is \”$strSmall\”.”;
echo $strBig;

?>

Thus, the output of the above program is

The name stored in $strSmall is “John Smith”.


STRING INDEXING

$string{index}

For example, take a look at the following program:

<?php
/* ch02ex07.php – demonstrates string indexing */
// Assign a name to $strName
$strName = “Walter Smith”;
// Output the fifth letter of the name
echo $strName{4};
?>

Objects
Objects are a powerful method of program organization. They are essentially what people are talking about when they refer to OOP or Object- Oriented Programming. Objects (and their definitions, called classes) are discussed in depth in Chapter 12, “Using Include Files (Local and Remote).”

server side versus client-side scripting

Server Side Versus Client Side Scripting
Server Side Versus Client Side Scripting


As already explained, PHP code is processed at the Web server before anything is returned to the browser. This is referred to as server-side processing. Most Web programming works this way: PHP, ASP, Perl, C, and others.

However, a few languages are processed by the browser after it receives the page. This is called client-side processing. The most common example of this is JavaScript.

NOTE : Despite the similarity in their names, Java and JavaScript are far from being the same.
Many Web developers are familiar with JavaScript, but this does not make them Java
programmers. It’s important to remember that these languages are not the same.

This can lead to an interesting problem with logic. The following example
demonstrates what I mean:

<script language=”JavaScript”>
if (testCondition())
{
<?php
echo “<b>The condition was true!</b>”;
?>
} else {
<?php
echo “<b>The condition was not true.</b>”;
?>
}
</script>


The resulting code from the previous snippet follows; notice that the
JavaScript has been left intact and untouched, but the PHP code has been
evaluated. PHP ignores the JavaScript code completely:

<script language=”JavaScript”>
if (testCondition())
{
<b>The condition was true!</b>
} else {
<b>The condition was not true.</b>
}
</script>

As you can see, this code will cause JavaScript errors when executed. Be
cautious when combining PHP and JavaScript code: It can be done, but it
must be done with attention to the fact that the PHP will always be evaluated
without regard for the JavaScript. To successfully combine the two, it’s

generally necessary to output JavaScript code with PHP.
The following example does just that:

<script language=”JavaScript”>
if (testCondition())
{
<?php
echo “document.write(‘<b>The condition was true!</b>’);”;
?>
} else {
<?php
echo “document.write(‘<b>The condition was not true.</b>’);”;
?>
}

</script>

As you can see, doing this gets complicated very quickly, so it’s best to avoid
combining PHP and JavaScript. However, the resulting code below shows

you that this will work.

<script language=”JavaScript”>
if (testCondition())
{
document.write(‘<b>The condition was true!</b>’);
} else {
document.write(‘<b>The condition was not true.</b>’);
}

</script>

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો...