Created
September 11, 2015 16:02
-
-
Save chriscalip/8b03b95fef8536860315 to your computer and use it in GitHub Desktop.
Example why to initiate variables first versus on-demand initiation inside loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// test for efqs | |
/** | |
* Root directory of Drupal installation. | |
*/ | |
define('DRUPAL_ROOT', getcwd()); | |
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
// turn error reporting back to normal | |
error_reporting(E_ALL); | |
// global $user; | |
// $user = user_load(1); | |
if (!function_exists('krumo')) { | |
has_krumo(); | |
} | |
krumo("foreach example a."); | |
foreach (chris_test() as $key) { | |
krumo($key); | |
} | |
krumo("foreach example b."); | |
$chris_test = chris_test(); | |
foreach ($chris_test as $key) { | |
krumo($key); | |
} | |
krumo("for loop example a."); | |
for ($i = 0; $i < chris_test2(); $i++) { | |
krumo($i); | |
} | |
krumo("for loop example b."); | |
$limit = chris_test2(); | |
for ($i = 0; $i < $chris_test2; $i++) { | |
krumo($i); | |
} | |
function chris_test() { | |
krumo(__FUNCTION__); | |
return array('a', 'b', 'c', 'd', 'e'); | |
} | |
function chris_test2() { | |
krumo(__FUNCTION__); | |
return 2; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment