Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-08-2010, 04:10 PM A few PHP question.
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi all,

I had a job interview today and got asked some PHP question. My PHP is ok but not super and there are the question I was unsure about so wanted to see if anyone could answer them for me.

Thanks in advance

1. How do you submit a form with no button?
4. What difference between echo() and Printf()
5. How can we get the current number of second from time?
6. How can we get the properties (size, width, height) of image using functions?
7. What the difference between $message and $$message?
8. What the difference between include () and include once ()?
9. What the difference between required () and include ()?
10. How would you increases the execution time of a PHP script?
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 10-08-2010, 04:35 PM Re: A few PHP question.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
1. Javascript (ex a link with an onclick event)

4. Read the manual echo printf. echo is not a function, it's a language construct.

5. time() will give you the number of seconds since the unix epoch (jan 1 1970).

6. getimagesize filesize

7. $$message refers to the variable with the name $message. So if $message is 'foo', $$message refers to $foo

8,9. Read the manual

10. sleep.

If you're applying for a job coding in PHP you should really know 4, 5, 7, 8 and 9 off the top of your head. The others are just a matter of checking the manual or using google.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 10-08-2010 at 04:52 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-08-2010, 05:00 PM Re: A few PHP question.
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi Nullpointer,

I answer most of these correct but I didnt get the job so wanted to make sure that I didnt mess the pre test I got a few wrong .

with regards to Question 7 does this then make $foo a variable if so why would you want to do this ?

and with regards to question 10 sleep slow down the excuation time how would this increase the exection time?

Thanks
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 10-08-2010, 05:20 PM Re: A few PHP question.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The same rules apply when dynamically referencing a variable. If $message is 'foo', referencing $$message will not implicitly define $foo and if $foo has not already been defined PHP will issue a notice. If you assign a value to $$message and $foo is not defined, $foo will be defined and the value assigned to it.
PHP Code:
$message 'foo';
echo $
$message//this will issue a notice

$message 'foo';
$
$message 'bar';

echo 
$foo//this will output bar
echo $$message//this will also output bar 
This isn't the most commonly used language feature, but knowing it can save you some time occasionally. Today, actually, I happened to use it:
PHP Code:
$data = array('a' => null'b' => null'c' => null);
foreach(
$data as $var => $dontuse)
     $
$var = &$data[$var]; 
What this does is takes each item in the data array and defines a variable for each key in the array. The variable is actually a reference to the element in the array. The following code:
PHP Code:
$data = array('a' => null'b' => null'c' => null);
foreach(
$data as $var => $dontuse)
     $
$var = &$data[$var];

$a 1;
$b 2;
$c 3;

print_r($data); 
will output
Code:
Array
(
    [a] => 1
    [b] => 2
    [c] => 3
)
Can you clarify what you're asking about sleep? All it does is halts the execution of a script for a certain amount of time (in seconds).
PHP Code:
$a 5;
$b 3;
sleep(3); //wait 3 seconds
echo $a $b
The total execution time of the above script will basically be 3 seconds since none of the operations (other than sleep) take any significant amount of time.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-09-2010, 01:34 PM Re: A few PHP question.
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
If you wanted to extend execution time (rather than the default 30 seconds as defined in php.ini) you would use the function set_time_limit()

printf() allows you to output a formatted string. for example:

PHP Code:
$number 10;
$who 'monkeys';
$what 'tree';
 
// Will output: There are 10 monkeys in the tree
printf('There are %d %s in the %s'$number$who$what);
 
 
// Will output: There are 0 10 in the monkeys
printf('There are %d %s in the %s'$what$number$who); 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-10-2010, 07:15 AM Re: A few PHP question.
Skilled Talker

Posts: 52
Name: Alex
Trades: 0
may be better that you, millwalll, would share with us your answers, not only questions.
elf2002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A few PHP question.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17711 seconds with 12 queries