Jump to content

efficiency to "$i" or to .$i


objnoob

Recommended Posts

Is it more efficient to concat strings to variables or include variables within a double quote enclosed string?

 

I've created a couple of classes to help take tons of coding off of the front end, and I've been pondering the idea of creating a container class to hold specific objects of some classes. My container class methods will do a lot of iterating through a lot of varient object names, and I'm questioning efficiency in regards to resolving the object variable's names...

 

Which is more efficient?

${"type_$i"}->setAttribute('readonly', 'readonly');
${'type_'.$i}->setAttribute('readonly', 'readonly');

Link to comment
https://forums.phpfreaks.com/topic/213239-efficiency-to-i-or-to-i/
Share on other sites

The reason being is that single quotes do not have to worry about parsing data so it is one less look up needed.

 

So the below is slower because you used double quotes  :P Basically, it doesn't matter use whatever you fancy! And even if you run into performance issues this will not be one of those area's you'll be putting focus on.

 

${"type_".$i}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.