PHP Questions

Q:

Why we use array_flip

Answer

array_flip exchange the keys with their associated values in array ie. Keys becomes values and values becomes keys.

<?php
$arrayName    = array("course1"=>"php","course2"=>"html");
$new_array    = array_flip($arrayName);
print_r($new_array);
?>

OUTPUT :

Array
(
[php]     => course1
[html]    => course2
)

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1905
Q:

How to set cookies?

Answer

setcookie('variable','value','time');
variable - name of the cookie variable
value     - value of the cookie variable
time       - expiry time

Example:
<?php
setcookie('Test',$i,time()+3600);
?>
Test - cookie variable name
$i - value of the variable 'Test'
time()+3600 - denotes that the cookie will expire after an one hour

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1877
Q:

What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

Answer

mysql_fetch_array:
Fetch a result row as an associative array and a numeric array.

mysql_fetch_object:
Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.

mysql_fetch_row():
Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1852
Q:

How do you define a constant?

Answer Via define() directive, like define ("MYCONSTANT", 100);
Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1837
Q:

What are the different types of errors in php?

Answer

Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behaviour.

Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.

Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behaviour is to display them to the user when they take place.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1831
Q:

Explain the changing file permission and ownership using PHP's chmod() function.

Answer

Chmod() is used for changing permissions on a file.


Syntax:


Chmod(file, mode)


Mode here specifies the permissions as follows:


The first number is always zero


The second number specifies permissions for the owner


The third number specifies permissions for the owner's user group


The fourth number specifies permissions for everybody else


Possible values (to set multiple permissions, add up the following numbers)


1 = execute permissions


2 = write permissions


4 = read permissions


Example:


// everything for owner, read for owner's group


chmod("test.txt",0740);

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1799
Q:

What is the functionality of md5 function in PHP?

Answer

Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1795
Q:

What is a .htacces file

Answer

 .htaccess is a configuration file running on Apache server.These .htaccess file used to change the functionality and features of apache web  server .

 e.g   .htaccess file used for url rewrite .

         .htaccess file used to make the site password protected.

         .htaccess file can restrict  some ip addresses ,so that on restricted ip adresses  site will not open.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

0 1778