Thursday, February 21, 2008

some php questions

1 When uploading a file using HTTP, which variable can be used to locate the file on PHP's local filesystem?


Answer...
None of the above
$_FILES['fieldname']['tmp_name']
$_FILES['fieldname']
$_FILES['fieldname'][0]['filename']
$_FILES['fieldname']['filename']

ans : $_FILES['fieldname']['tmp_name']


2 Which of the following SQL statements will improve SQLite write performance?


Answers: (choose 2)
PRAGMA locking_mode = "Row";
PRAGMA count_changes = Off;
PRAGMA default_synchronous = Off;
PRAGMA default_synchronous = On;
PRAGMA locking_mode = "Table";

Ans:

3 What is the best way to iterate and modify every element of an array using PHP 5?

Answer...
You cannot modify an array during iteration
for($i = 0; $i < count($array); $i++) { /* ... */ }
foreach($array as $key => &$val) { /* ... */ }
foreach($array as $key => $val) { /* ... */ }
while(list($key, $val) = each($array)) { /* ... */

4 What is the primary benefit of a SAX-based XML parser compared to DOM?




Please answer through the comments I will make it publish on blog..............

6 comments:

  1. for($i = 0; $i < count($array); $i++) { /* ... */ } is correct answer

    ReplyDelete
  2. for question 2:

    PRAGMA count_changes = Off;
    PRAGMA default_synchronous = Off;

    ReplyDelete
  3. for question 1:
    $_FILES['fieldname']['tmp_name']

    ReplyDelete
  4. nkhanchandani said...
    for($i = 0; $i < count($array); $i++) { /* ... */ } is correct answer
    for($i = 0; $i < count($array);
    Sorry, I don't think so.
    for($i = 0; $i < count($array); $i++) { /* DO WHAT EXACTLY??? */ }
    Can you give an example simpler than...

    $array =range('A', 'Z');
    foreach($array as $key=> &$value){
    $value= $i++;
    }
    print_r($array);

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. tjmcd1963, read that - What is the best way to iterate and MODIFY

    foreach needs array_keys to modify input array, so the right answer is for(...)

    ReplyDelete

Please put your comments here. your questions, your suggestions, also what went wrong with me.