[TYPO3-dev] Including files to the <head> once

Dmitry Dulepov dmitry at typo3.org
Sat Jan 3 14:22:48 CET 2009


Hi!

Steffen Kamper wrote:
> This is the reasons why many use additionalHeader[9999] to ensure that
> script is include late. Using the path as identifier makes inclusion by
> alphabet which doesn't make sense.

In fact it does not. PHP arrays are in fact unordered maps (they are not ordered by keys). Values in the array are stored in the order of adding, not in the order of keys. Try running this script:
================
<?php

$testArray['a'] = 'file a';
$testArray['b'] = 'file b';

foreach ($testArray as $key => $value) {
        echo $key . '=>' . $value . chr(10);
}

unset($testArray);

$testArray['b'] = 'file b';
$testArray['a'] = 'file a';

echo '===' . chr(10);

foreach ($testArray as $key => $value) {
        echo $key . '=>' . $value . chr(10);
}

unset($testArray);

$testArray[2] = 'file b';
$testArray[1] = 'file a';

echo '===' . chr(10);

foreach ($testArray as $key => $value) {
        echo $key . '=>' . $value . chr(10);
}

?>
================

The result:
----------------
a=>file a
b=>file b
===
b=>file b
a=>file a
===
2=>file b
1=>file a
----------------

As you see even higher numeric key does not make its value appear after the lower value key. Using 9999 for this purpose does not make any sense. The only way to have sorted array is to use sort(), asort() or any other sorting function.

-- 
Dmitry Dulepov
TYPO3 core team
In the blog: http://typo3bloke.net/post-details/why_your_typo3_installation_can_be_slow/
My TYPO3 book: http://www.packtpub.com/typo3-extension-development/book




More information about the TYPO3-dev mailing list