Add array loop
Add Global variables Add is array ? Add string concat Signed-off-by: Adrien <adrien.ph@gmail.com>
This commit is contained in:
parent
8c642ecb39
commit
5ca89966d0
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
// foreach_v() n'est pas dans le graph car son éxecution prends -1% du temps d'éxecution total
|
||||
|
||||
$array = array('42' => 'The Truth Is Out There', 'json' => array('toi' => 'une case en moins', 'voir trois'), 'toujours là');
|
||||
|
||||
function foreach_kv()
|
||||
{
|
||||
global $array;
|
||||
|
||||
foreach ($array as $key => $value);
|
||||
}
|
||||
|
||||
function foreach_kPv()
|
||||
{
|
||||
global $array;
|
||||
|
||||
foreach ($array as $key => &$value);
|
||||
}
|
||||
|
||||
function foreach_v()
|
||||
{
|
||||
global $array;
|
||||
|
||||
foreach ($array as $value);
|
||||
}
|
||||
|
||||
function while_k()
|
||||
{
|
||||
global $array;
|
||||
|
||||
while (list($key) = each($array));
|
||||
}
|
||||
|
||||
function for_k()
|
||||
{
|
||||
global $array;
|
||||
|
||||
$key = array_keys($array);
|
||||
$size = sizeof($key);
|
||||
|
||||
for ($i=0; $i < $size; $i++);
|
||||
}
|
||||
|
||||
foreach_kv();
|
||||
foreach_kPv();
|
||||
foreach_v();
|
||||
while_k();
|
||||
for_k();
|
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
// Pour plus d'équité variables_def() et staticVariables_def() sont appelé 10 fois comme php::define
|
||||
// En utilisant des variables statiques dans une fonction il est aussi possible de les redeffinires
|
||||
// Le defaut des fonctions de variables est qu'il faut optimiser les appeles comme avec une BDD sinon on sur charge
|
||||
|
||||
function constants_def()
|
||||
{
|
||||
define("hall0000", "f<e");
|
||||
define("hall1000", "yrk");
|
||||
define("hall2000", "sj,");
|
||||
define("hall3000", "zrtzyj");
|
||||
define("hall4000", "rzthnj");
|
||||
define("hall5000", "ioù");
|
||||
define("hall6000", "att");
|
||||
define("hall7000", "4tb2");
|
||||
define("hall8000", "zzrtny2");
|
||||
define("hall9000", ",ty");
|
||||
}
|
||||
|
||||
function variables_def($arg)
|
||||
{
|
||||
$hall0000 = "zrtb";
|
||||
$hall1000 = "zrtny2";
|
||||
$hall2000 = "4zrty";
|
||||
$hall3000 = "4!ç=$";
|
||||
$hall4000 = "ynzi2";
|
||||
$hall5000 = "!=ç";
|
||||
$hall6000 = "zl";
|
||||
$hall7000 = "tlzyyyy";
|
||||
$hall8000 = "zlyt";
|
||||
$hall9000 = "zlryurtj";
|
||||
|
||||
return ${$arg};
|
||||
}
|
||||
|
||||
function staticVariables_def($arg)
|
||||
{
|
||||
static $hall0000 = "synuu";
|
||||
static $hall1000 = "op:t";
|
||||
static $hall2000 = "zrty;";
|
||||
static $hall3000 = ";zrty";
|
||||
static $hall4000 = "42ld";
|
||||
static $hall5000 = "4;tpm,2";
|
||||
static $hall6000 = "qeyryur";
|
||||
static $hall7000 = "(rsy,)";
|
||||
static $hall8000 = "4ç-;e";
|
||||
static $hall9000 = ",-r";
|
||||
|
||||
return ${$arg};
|
||||
}
|
||||
|
||||
function constants_used()
|
||||
{
|
||||
constants_def();
|
||||
|
||||
$a = hall5000;
|
||||
}
|
||||
|
||||
function variables_used()
|
||||
{
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
$a = variables_def("hall".$i."000");
|
||||
echo "string";
|
||||
}
|
||||
}
|
||||
|
||||
function staticVariables_used()
|
||||
{
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
$a = staticVariables_def("hall".$i."000");
|
||||
}
|
||||
}
|
||||
|
||||
constants_used();
|
||||
variables_used();
|
||||
staticVariables_used();
|
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
function isArray()
|
||||
{
|
||||
$iterations = 100000;
|
||||
$array = array('foo' => 'bar', 'item', 'Value');
|
||||
|
||||
for ($i = 0; $i < $iterations; ++$i) {
|
||||
if (is_array($array)) {}
|
||||
}
|
||||
}
|
||||
|
||||
function castArray()
|
||||
{
|
||||
$iterations = 100000;
|
||||
$array = array('foo' => 'bar', 'item', 'Value');
|
||||
|
||||
for ($i = 0; $i < $iterations; ++$i) {
|
||||
if ((array) $array == $array) {}
|
||||
}
|
||||
}
|
||||
|
||||
function gettypeArray()
|
||||
{
|
||||
$iterations = 100000;
|
||||
$array = array('foo' => 'bar', 'item', 'Value');
|
||||
|
||||
for ($i = 0; $i < $iterations; ++$i) {
|
||||
if (gettype($array) == "array") {}
|
||||
}
|
||||
}
|
||||
|
||||
isArray();
|
||||
castArray();
|
||||
gettypeArray();
|
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
function implodeArr()
|
||||
{
|
||||
$string = '';
|
||||
$array = array();
|
||||
|
||||
for ($i = 0; $i < 100000; ++$i) {
|
||||
$array[] = 'MyLittlePony != 42 ';
|
||||
}
|
||||
|
||||
$string = implode($array);
|
||||
}
|
||||
|
||||
function classic()
|
||||
{
|
||||
$string = '';
|
||||
|
||||
for ($i = 0; $i < 100000; ++$i) {
|
||||
$string .= 'MyLittlePony != 42 ';
|
||||
}
|
||||
}
|
||||
|
||||
function reDefinition()
|
||||
{
|
||||
$string = '';
|
||||
|
||||
for ($i = 0; $i < 100000; ++$i) {
|
||||
$string == $string.'MyLittlePony != 42 ';
|
||||
}
|
||||
}
|
||||
|
||||
implodeArr();
|
||||
classic();
|
||||
reDefinition();
|
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Loading…
Reference in New Issue