php_zend_cert Flashcards
PHP_START_TAG
$array1 = $array2 = array(“img12.png”, “img10.png”, “img2.png”, “img1.png”); asort($array1); var_dump($array1); PHP_END_TAG
doesn’t sort in an order a human would expect. What function should we use instead ?
bool natsort ( array &$array ) will output array 3 => string ‘img1.png’ (length=8) 2 => string ‘img2.png’ (length=8) 1 => string ‘img10.png’ (length=9) 0 => string ‘img12.png’ (length=9)
PHP_START_TAG $chaine = “Hello World”; $bool = ( $chaine[1] === $chaine{1} ); PHP_END_TAG What is the value of $bool ?
TRUE
PHP_START_TAG $details[] = ‘Mehdi’; $details[] = ‘Matthieu’; $details[] = ‘cuillère’; … echo “$nom1 et $nom2 mangent à l’aide d’une $ustensile
“; PHP_END_TAG Write the missing line that will allow a correct display.
list ($nom1, $nom2, $ustensile) = $details;
PHP_START_TAG $long = ‘la–li–lou–la–lo’; $delimiter=’–’; $limit=-2; $explodedArray = explode($delimiter,$long,$limit); PHP_END_TAG What does $explodedArray contain ?
array 0 => string ‘la’ (length=2) 1 => string ‘li’ (length=2)
PHP_START_TAG $long = ‘la–li–lou–la–lo’; $delimiter=’–’; $limit=0; $explodedArray = explode($delimiter,$long,$limit); PHP_END_TAG What does $explodedArray contain ?
array 0 => string ‘la–li–lou–la–lo’ (length=19) If the limit parameter is zero, then this is treated as 1.
PHP_START_TAG $long = ‘la–li–lou–la–lo’; $delimiter=’–’; $limit=3; $explodedArray = explode($delimiter,$long,$limit); PHP_END_TAG What does $explodedArray contain ?
array 0 => string ‘la’ (length=2) 1 => string ‘li’ (length=2) 2 => string ‘lou–la–lo’ (length=11)
PHP_START_TAG $numbers = array(“0”, “1”, “2”, “3”); $value= 2 ; echo (in_array ( $value , $numbers ,TRUE ) ? “$value is a number” : “$value is not a number”); PHP_END_TAG What does this code display ?
2 is not a number
PHP_START_TAG $os = array(“Mac”, “NT”, “Irix”, “Linux”); echo (in_array ( “mac” , $os ) ? ‘mac is an OS’ : ‘mac is not an OS’); PHP_END_TAG What does this code display ?
mac is not an OS
PHP_START_TAG $search_array = array(‘first’ => null, ‘second’ => 4); $returnValue = array_key_exists(‘first’, $search_array); PHP_END_TAG What is the value of $returnValue ?
true. You should use isset($search_array[‘first’]) if you want to return false.
PHP_START_TAG $subject = “pitimi bilipi waowao ao wawao pikin iki owawa”; $mask = “aow”; $longueurPermierWawa = strspn ( $subject , $mask , …. ); echo $longueurPremierWawa; PHP_END_TAG How should I complete this code in order to correctly use strspn() ?
strpos($subject, ‘w’) Fo reference, int strspn ( string $subject , string $mask [, int $start [, int $length]] ) $start and $length can have negative values
PHP_START_TAG $var = ‘lala’ if ( gettype ( $var ) == ‘lala’) {echo “$var is a string”;} PHP_END_TAG Is there a better way to do the same thing ?
Use is_string();
PHP_START_TAG function incrementVariable() { static $nb = 0; $nb++; return $nb; } echo incrementVariable(); incrementVariable(); PHP_END_TAG What does this code display ?
12
PHP_START_TAG while (true) { while (true) { … } } PHP_END_TAG What instruction can you write do get out of the loop ?
break(2);
Can PHP include distant files ?
Yes, with allow_url_fopen set to 1 in php.ini. But default is 0. It cannot be changed with ini_set()
Cite a function that generates a random number.
int mt_rand ( int $min =0 , int $max = mt_getrandmax() ) int rand ( void ) int rand ( int $min , int $max )
Cite the three functions that allow your function to access the passed arguments.
int func_num_args(void) mixed func_get_arg(int $arg_num ) array func_get_args ( void )
Give an easy way to filter user input.
string strip_tags ( string $str [, string $allowable_tags] ) Because strip_tags() does not actually validate the HTML, partial, or broken tags can result in the removal of more text/data than expected.
Has PHP got a pointer system ?
No, not like C. It uses reference.
Hopw do you delete a folder ?
bool rmdir ( string $dirname [, resource $context] )
How are NULL, FALSE and numbers equal to 0 transtyped into a string ?
They are transtyped to an empty string (not to the 0 char)
How are sessions saved ?
depends on session.save_handler in php.ini. Generally, session.save_handler=’files’.
How could you access a variable outside of its normal scope
Use superglobal array $GLOBALS[]. Use of register_globals is deprecated, and set to off in PHP.ini
How do I check if a variable is an array ?
is_array($var)
How do I check if a variable is an object ?
is_object()
How do I know the data type of a variable ?
gettype($var) or is_string($var) is_bool($var) is_int($var) is_integer($var) etc
How do transtype a variable’s value into another variable
strval(), intval(), doubleval(), floatval(), etc
How do you calculate the sum of values in an array ?
number array_sum ( array $array )
How do you check if the given key or index exists in the array ?
bool array_key_exists ( mixed $key , array $search )
How do you check if the object or class has a given property ?
bool property_exists ( mixed $class , string $property ) $class : The class name OR an object of the class to test for
How do you convert \n character to HTML ?
nl2br()
How do you convert all applicable characters to HTML entities ? What parameter defines the applicable charset ?
string htmlentities ( string $string [, int $flags = ENT_COMPAT [, string $charset [, bool $double_encode = true]]] )
How do you count all the different values of an array ?
array array_count_values ( array $input ) Returns an associative array using the values of $input as keys and their frequency as values.
How do you create a constant ?
define(“CONSTANT”,”value”)
How do you delete a file ?
bool unlink ( string $filename [, resource $context] )
How do you destroy a variable ?
unset($var)
How do you do?
Splendid !
How do you force a variable to be transtyped ?
* (int), (string), etc, before the variable * settype($variable, $dataType)
How do you make a copy of an object ?
$copy = clone $original;
How do you merge arrays ?
array array_merge( array $array1 [, array $array2 [, array $…]] )