PHP: Pre-increment vs Post-increment
If the idea is to increment a variable and not care about the intermediate value, then pre-increment might be faster than post-increment. Here is why:
e-g incrementing an object variable
$o->aa++ vs ++$o->aa
The opcodes for post-increment:
3 POST_INC_OBJ ~1 !0, 'aa'
4 FREE ~1has to save the incoming value (for later return) and do the actual increment. The returned value has to be "freed" even though it is not being used. Optimizers might look at these patterns and change them to pre-increment. If optimizers are not used, then this will end up wasting extra cycles.
The opcodes for pre-increment:
3 PRE_INC_OBJ !0, 'aa'Nothing is returned and hence does not have to be freed.
e-g increment a variable
$i++ vs ++$i
8 POST_INC ~3 !1
9 FREE ~3 11 PRE_INC !1The PHP opcodes can be easily dumped using tools like vld.
Group Add More: Simulate clicking on group of multi-value fields
A custom content type that we built recently had multiple fields which accepted unlimited values. Some of these fields were grouped together and expected to accept values together.
The fix to this problem is rather simple. Simulate clicking on individual "Add More" buttons. We generalized this idea and create a jQuery plugin to facilitate this on any group of multi-value fields inside a container. This is supported for Drupal 6 & 7. Use the plugin from the approriate github branch from: https://github.com/nkmani/group-add-more (1.0 is for D6 and 2.0 is for D7).
To use this plugin:
Include the jquery.group-add-more.js file (both development as well as minified versions are available) in your theme.
Include the javascript snippet to attach the plugin to the container that has the add-more buttons.
The rendered group field would look like as shown below.