Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

hinom

Challenge for ZEND PHP5 Certification - 032

Exercise 32  

2 votos

  1. 1. Which composite data types are supported by php?

    • A. Array
      1
    • B. Enumeration
      0
    • C. List
      0
    • D. Object
      1
    • E. Integer
      1


Recommended Posts

Exercise 32

 

Which composite data types are supported by php?

 

A. Array

B. Enumeration

C. List

D. Object

E. Integer

Compartilhar este post


Link para o post
Compartilhar em outros sites

Answer: A, C, D, E

 

Explanation

 

In computer science, composite types are datatypes which can be constructed in a programming language out of that language's primitive types and other composite types. The act of constructing a composite type is known as composition.

http://wikipedia.org/wiki/Composite_type

 

 

Variables can store data of different types in order to make different things

 

In PHP there are these data types:

 

- Integer: A whole number without fractions, the range of integers allowed depends on ur operating system, but in general u can use it between the range -2 Billion up to + 2 Billion

- Floating point number (Real number or float): A number which is usually not a whole number and includes decimal places

- Character string: A series of single characters, there is no limit fot the string length

- Boolen: A true or false value.

 

About Boolean:Boolean data type represents two possible states (TRUE or FALSE) they are used mainly in conditions, PHP considers the following values FALSE:

 

- the string FALSE/false

- the integer 0

- the float 0.0

- any empty string

- the one-character string 0

- the constant NULL

 

Any other values in a Boolean variable are considered to be TRUE

 

 

[buAssigning data types:[/u]

Unlike many programming languages u don't 've to assign the variable type while creating it, PHP will evaluates the data when assigning it to the variable and then it will store it appropriate type.

 

PHP also converts the type of data if it found any need for that autoatically, such as if u try to add integer number with floating point number, remember that in many langauges such as C++ or Jave this will be considered as an error!

 

 

Type casting:

On rare occasion, PHP will guess the type badly for the data. so in this case u can specify how u want the PHP to store the data rather than let PHP decide for itself; this is called type casting.

 

 

 

$new_variable_name = (data_type) $old_variable_name;

 

note1: be careful while doing type casts, not to get unexpected result. i.e. when u cast a float into integer u it lose its decimal places ,,, if u convert 2.9 to integer u will get 2 only and u will lose 0.9 value,,, so PAY ATTENTION!

note2: u can find the data type for any variable using

 

 

 

var_dump($variable_name);

 

it will display the type(value in the variable) for numbersand

 

type (number of characters) "value" for strings

 

Example:

 

<?php
$string_variable= "Hello!";

echo "String variable with 6 characters <br>";

var_dump($string_variable);

echo "<br>"

;echo "Number variable with 5 digits and the value = 12345 <br>";

$number_variable= 12345;

var_dump($number_variable);

?>

The output for the above example:

 

String variable with 6 characters

string(6) "Hello!"

Number variable with 5 digits and the value = 12345

int(12345)

http://me2learn.wordpress.com/2008/09/04/data-types/

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.