PHP Classes

File: testArrayMap.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   Array Map   testArrayMap.php   Download  
File: testArrayMap.php
Role: Example script
Content type: text/plain
Description: example script
Class: Array Map
Traverse arrays to call functions for each entry
Author: By
Last change:
Date: 5 years ago
Size: 1,839 bytes
 

Contents

Class file image Download
<?php
require_once('ArrayMap.php');



$aroutine=<<<'EOF'
if(isset($u)) $u++;
else $u=0;
array_multisort(%placeholder%,SORT_NUMERIC,SORT_DESC);
$GLOBALS['key'.$u]= %key%; //make the key available outside just for an example.It is just the same as pass a reference as argument
// %placeholder%=array_sum(%placeholder%);
EOF;

$vroutine=<<<'EOF'
global $myrefence;
$myrefence++;
if(is_string(%placeholder%)) %placeholder%=strtoUpper(%placeholder%);
elseif (is_numeric(%placeholder%)){
    %placeholder%*=%placeholder%;
}
else {

    %placeholder%=is_bool(%placeholder%)?(%placeholder%===true?'TRUE':'FALSE'):%placeholder%;
    %placeholder%=is_object(%placeholder%)?(array)%placeholder%:%placeholder%;
    if(is_array(%placeholder%)) eval($aroutine);
    if(!isset($aroutine))
        %placeholder%=is_array(%placeholder%)?array_sum(%placeholder%):%placeholder%;
   
   
}

EOF;

echo
'<pre>';
$array[0]=array(range(1,10),range(20,-20,2));
$array[1]=range(1,10);
$array[2]=range(1,10);
$array[3]=range(1,10);
$array[4]=[[['Bigbadaboom',[[['badaboom']]]],'Gigabigboom']];
$array[]=(object)[1,2,3];
$array[]=(bool)[1,2,3];
$array[]=(bool)[];


print_r(arrayMap::aroutine($vroutine,$array));

$myrefence=null;//will help me count the number of single values in the array including in sub_arrays exactly as the function count()
print_r(arrayMap::anvroutine($aroutine,$vroutine,$array));

var_dump($myrefence);
foreach(
$GLOBALS as $key=>$value){
    if(
strpos($key,'key')===0)
        echo
"key: $key =>$value
            <br>"
;
   
}

print_r(arrayMap::aroutine($vroutine,null,$array));

$myrefence=null;//will help me count the number of single values in the array including in sub_arrays exactly as the function count()

print_r(arrayMap::anvroutine($aroutine,$vroutine,null,$array));

var_dump($myrefence);




?>