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
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}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.