PHP Classes

File: examples/ExtractListAndCompact.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Mo´se  >  PHP Dictionary to Array class  >  examples/ExtractListAndCompact.php  >  Download  
File: examples/ExtractListAndCompact.php
Role: Example script
Content type: text/plain
Description: example script
Class: PHP Dictionary to Array class
Manipulate value collections as arrays or objects
Author: By
Last change:
Date: 3 years ago
Size: 4,184 bytes
 

Contents

Class file image Download
Here is a simple example on extraction to global variable details.Of course you can use any of the PHP <br>
Native extract function Flags as stated in the doc <?php
require_once('./../xdict.class.php');
echo
'<pre>';
highlight_string('<?php
$x=xdict(0,\'_\'/*can be empty string*/,true/*or false*/,true/*or false*/,10 /*will limit number of entry to 10,by default it is unlimited*/);
        for ($i=0;$i<15;$i++){
            $x[]=$i*3;
        }
        var_dump($x);
       
$x->extract();
echo $_1;echo "<br>";
echo $_2;echo "<br>";
echo $_3;echo "<br>";
echo $_4;echo "<br>";
echo $_5;echo "<br>";
echo $_6;echo "<br>";
echo $_7;echo "<br>";
echo $_8;echo "<br>";
echo $_9;echo "<br>";
// echo $_10;echo "<br>";//print undefined it is normal because the xDict object is limited to ten entries actually

$x->extract(EXTR_PREFIX_SAME,\'xdict\');
echo $xdict__1;echo "<br>";
echo $xdict__2;echo "<br>";
echo $xdict__3;echo "<br>";
echo $xdict__4;echo "<br>";
echo $xdict__5;echo "<br>";
echo $xdict__6;echo "<br>";
echo $xdict__7;echo "<br>";
echo $xdict__8;echo "<br>";
echo $xdict__9;echo "<br>";
// echo $_10;echo "<br>";//print undefined it is normal because the xDict object is limited to ten entries actually
$x->extract(EXTR_REFS|EXTR_PREFIX_SAME,\'xDict\');
for($i=0;$i<10;$i++){
    ${\'xDict__\'.$i}=1;
}

var_dump($x);

$x->extract(EXTR_SKIP);
echo $_1;echo "<br>";
echo $_2;echo "<br>";
echo $_3;echo "<br>";
echo $_4;echo "<br>";
echo $_5;echo "<br>";
echo $_6;echo "<br>";
echo $_7;echo "<br>";
echo $_8;echo "<br>";
echo $_9;echo "<br>";

$x->extract(EXTR_OVERWRITE);
echo $_1;echo "<br>";
echo $_2;echo "<br>";
echo $_3;echo "<br>";
echo $_4;echo "<br>";
echo $_5;echo "<br>";
echo $_6;echo "<br>";
echo $_7;echo "<br>";
echo $_8;echo "<br>";
echo $_9;echo "<br>";
?>'
);
$x=xdict(0,'_'/*can be empty string*/,true/*or false*/,true/*or false*/,10 /*will limit number of entry to 10,by default it is unlimited*/);
        for (
$i=0;$i<15;$i++){
           
$x[]=$i*3;
        }
       
var_dump($x);
       
$x->extract();
echo
$_1;echo "<br>";
echo
$_2;echo "<br>";
echo
$_3;echo "<br>";
echo
$_4;echo "<br>";
echo
$_5;echo "<br>";
echo
$_6;echo "<br>";
echo
$_7;echo "<br>";
echo
$_8;echo "<br>";
echo
$_9;echo "<br>";
// echo $_10;echo "<br>";//print undefined it is normal because the xDict object is limited to ten entries actually

$x->extract(EXTR_PREFIX_SAME,'xdict');
echo
$xdict__1;echo "<br>";
echo
$xdict__2;echo "<br>";
echo
$xdict__3;echo "<br>";
echo
$xdict__4;echo "<br>";
echo
$xdict__5;echo "<br>";
echo
$xdict__6;echo "<br>";
echo
$xdict__7;echo "<br>";
echo
$xdict__8;echo "<br>";
echo
$xdict__9;echo "<br>";
// echo $_10;echo "<br>";//print undefined it is normal because the xDict object is limited to ten entries actually
$x->extract(EXTR_REFS|EXTR_PREFIX_SAME,'xDict');
for(
$i=0;$i<10;$i++){
    ${
'xDict__'.$i}=1;
}

var_dump($x);

$x->extract(EXTR_SKIP);
echo
$_1;echo "<br>";
echo
$_2;echo "<br>";
echo
$_3;echo "<br>";
echo
$_4;echo "<br>";
echo
$_5;echo "<br>";
echo
$_6;echo "<br>";
echo
$_7;echo "<br>";
echo
$_8;echo "<br>";
echo
$_9;echo "<br>";

$x->extract(EXTR_OVERWRITE);
echo
$_1;echo "<br>";
echo
$_2;echo "<br>";
echo
$_3;echo "<br>";
echo
$_4;echo "<br>";
echo
$_5;echo "<br>";
echo
$_6;echo "<br>";
echo
$_7;echo "<br>";
echo
$_8;echo "<br>";
echo
$_9;echo "<br>";

highlight_string('<?php
$y=xdict(0,\'k\');
for ($i=0;$i<3;$i++){
    $y[]=$i*3;
}
$y->print_xr();
$y->listvar($min,$middle,$max);// PHP list structure equivalent in method but more restrictive as it uses references
var_dump($min,$middle,$max);
$y->strict=false;
$y->compact(\'min\',\'middle\',\'max\',array(\'x\'));//PHP compact function equivalent in method. work only with strict mode off
$y->print_xr();
?>'
);
$y=xdict(0,'k');
for (
$i=0;$i<3;$i++){
   
$y[]=$i*3;
}
$y->print_xr();
$y->listvar($min,$middle,$max);// PHP list structure equivalent in method but more restrictive as it uses references
var_dump($min,$middle,$max);
$y->strict=false;
$y->compact('min','middle','max',array('x'));//PHP compact function equivalent in method. work only with strict mode off
$y->print_xr();
?>

For more information send a message to info at phpclasses dot org.