PHP: Types

Derek Bridge

Department of Computer Science,
University College Cork

PHP: Types

Aims:

Data types

PHP's string data type

PHP's numeric data types

PHP's integer data type

PHP's float data type

Variables and their types

Example program

Form data arrives as strings

Explicit type conversion

The finished program

$num_of_students = (int) $_GET['num_of_students'];
$num_of_staff = (int) $_GET['num_of_staff'];

$num_of_students_per_staff = $num_of_students / $num_of_staff;
   
echo '<p>';
echo $num_of_students_per_staff;
echo '</p>';

But that's not the end of the story

Class exercise

Variables and their types

Variables and their types