Click to See Complete Forum and Search --> : ermm ' over "


Kyleva2204
03-26-2006, 09:30 PM
Ok, so I heard that you only use " when theres a variable involved, because it takes up time... other wise use '.. right? well.. what if you have \n?.. THe ' doesn't work with \n.. so should I use " or say 'this text.. + new line ' . "\n"; hm? This is probably a dumb question, but up until now, I thought I knew php pretty well, but it turns out theres much for me to learn, so thats why I'm asking.. I'm expecting that it wold be easier to use " because then it doesn't compute two different things..

hehe thanks..
Kyle

NogDog
03-26-2006, 09:57 PM
The time difference - if any - is so minimal that I wouldn't worry about it unless I were programming a mission-critical realtime system. And if I were doing that, I wouldn't be using PHP. (You're probably talking savings of a few milliseconds or even just microseconds, depending on the server where your code is running).

Probably of much more importance 99.99% or so of the time is to keep your code as easy to read as possible by you, so that you can make changes at some later time with a minimum of agony.

Kyleva2204
03-26-2006, 11:16 PM
Hm- i was just reading some things online, and they are like ommeeegod save time!! >_<!!!! so yeah- just questioning it! :P

NogDog
03-27-2006, 04:17 AM
Try this little test, and refresh the page a few times (to account for random variations in processing time):

<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time0 = microtime_float(); // "prime the pump"
$time1 = microtime_float();
echo '<p>This is a test.';
echo 'It is only a test.';
echo 'This is the end of the test</p>';
$time2 = microtime_float();
echo "<p>This is a test.";
echo "It is only a test.";
echo "This is the end of the test</p>";
$time3 = microtime_float();
echo <<<EOD
<p>This is a test.
It is only a test.
This is the end of the test</p>
EOD;
$time4 = microtime_float();
echo sprintf("<p>Test 1 took %f seconds</p>", $time2 - $time1);
echo sprintf("<p>Test 2 took %f seconds</p>", $time3 - $time2);
echo sprintf("<p>Test 3 took %f seconds</p>", $time4 - $time3);
?>

Typical output on my PC was:

Test 1 took 0.000050 seconds
Test 2 took 0.000049 seconds
Test 3 took 0.000056 seconds

Hardly worth much worry about which is faster, I think?

SpectreReturns
03-28-2006, 12:24 AM
I used to use ' but then I started C++ and C# and what not, so now I use " but don't use the variable parsing ability. (sorry, it seemed relevant when I typed it)