Jump to content

PHP FAQ's


Aryacooldude

Recommended Posts

Q:-What is a PHP File?

Ans:- PHP files may contain text, HTML tags and scripts.

PHP files are returned to the browser as plain HTML.

PHP files have a file extension of ".php", ".php3", or ".phtml".

Q:-What is PHP relation to PHP/FI?

Ans:- PHP is the successor to PHP/FI 2.0

Q:-What is the difference between PHP and JavaScript?

Ans:- javascript is a client side scripting language, so javascript can make popups and other things happens on someone’s PC. While PHP is server side scripting language so it does every stuff with the server.

Q:-What does a special set of tags do in PHP?

Ans:-The output is displayed directly to the browser.

Q:-What’s the difference between include() and require()?

Ans:-It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

Q:-How do you define a constant?

Ans:-Via define() directive, like define (“MYCONSTANT”, 1000);

Q:-How do you pass a variable by value?

Ans:-Just like in C++, put an ampersand in front of it, like $a = &$b

Q:-When are you supposed to use endif to end the conditional statement?

Ans:-When the original if was followed by : and then the code block without braces.

Q:-How do I find out the number of parameters passed into function?

Ans:- func_num_args() function returns the number of parameters passed in.

Q:-Are objects passed by value or by reference?

Ans:-Everything is passed by value.

Q:-How do you call a constructor for a parent class?

Ans:-parent::constructor($value)

Q:-What’s the special meaning of __sleep and __wakeup?

Ans:-__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

Q:-Would you initialize your strings with single quotes or double quotes?

Ans:- Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

Q:-How come the code works, but doesn’t for two-dimensional array of mine?

Ans:-Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.

Q:-What is the difference between characters 23 and x23?

Ans:-The first one is octal 23, the second is hex 23.

Q:-For printing out strings, there are echo, print and printf. Explain the differences.

Ans:-echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo,print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.

Q:-How can you create an array of numbers easily?

Ans: If we want to create an array of consecutive numbers in PHP, then we can do it the long hand way.

<? php

$myarray = array (1, 2, 3, 4, 5, 6, 7, 8, 9);

?>

Or you can do it the easy way, using the range function, which you simply pass the first and last value in the consecutive range. So this is equivalent to the above code:

<? php

$myarray = range (1, 9);

?>

When you want an array containing the numbers 1 to 1, 000 - you'll be glad you learned about this function, so try this.

Link to comment
Share on other sites

more about a PHP file A PHP file may contain text, HTML tags and scripts. It is returned to the browser in form of plain HTML code. An Example of PHP file are given below: <html> <head><title>PHPExample</title></head> <body> <h1><?php echo "Welcome in PHP world"; ?></h1> <?php $txt = "This is my first PHP script"; /* statement */ echo $txt; ?> </body> </html>

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...