Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
<?php
# Arrays mit variabler Dimension Werte zuweisen
# 21.10.2005
$keys = array('hallo', 'test', 'bla', 'blubb', 'foo', 'bar');
$keys = implode("']['", $keys);
eval("\$arr['$keys'] = 'Wert';");
print_r($arr);
?>
<?php
# Arrays mit variabler Dimension Werte zuweisen
# 21.10.2005
function setArrayValue(&$arr, $keys, $value)
{
eval("\$arr['".implode("']['", $keys)."'] = $value;");
}
$arr = array();
$keys = array('hallo', 'test', 'bla', 'blubb', 'foo', 'bar');
$value = 'Wert';
setArrayValue($arr, $keys, $value);
print_r($arr);
?>
class dircontentlist {
//parameters
public $dirmap;
public function setArrayValue($keys, $value, $file=false){
if ($file==false){
return eval("\$this->dirmap['".implode("']['", $keys)."'] = $value;");
}
else {
return eval("\$this->dirmap['".implode("']['", $keys)."'][] = $value;");
}
}
public function __construct($rootpath,$keys=""){//create tree
$tmpdir=opendir($rootpath);//open rootpath
if ($keys==""){
$keyvars[]="root";
}
else {
$keyvars[]=$keys;
}
while ($mapvar=readdir($tmpdir)){
if (($mapvar!=".") && ($mapvar!="..")){//is valid var
if (is_dir($rootpath."/".$mapvar)){//is(are) dir(s)
$this->setArrayValue($keyvars, $mapvar);
//$this->dirmap[$arrkeyvar][$mapvar]=$this->__construct($rootpath."/".$mapvar,$mapvar,$testvar);
}
else {//is(are) file(s)
##$this->setArrayValue($keyvars, $mapvar, true);
//$this->dirmap[$arrkeyvar][]=$mapvar;
}
}
}
closedir($tmpdir);
}
}//end class
class dircontentlist{
public $dirmap;
public function __construct($rootpath){
$this->buildmap($rootpath);
echo "Rootpath: ".$rootpath."\n";
}
public function setArrayValue(&$arr, $keys, $value, $file=false){
if ($file==false){
eval("\$arr['".implode("']['", $keys)."'] = $value;");
}
else {
eval("\$arr['".implode("']['", $keys)."'][] = $value;");
}
}
public function buildmap($path){//create tree
$patharray = explode("/",$path);
$documentroot = explode("/",$_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF']);
$pathlevel = array_diff($patharray, $documentroot); array_shift($pathlevel);
print_r($pathlevel);
$dir=opendir($path);//open rootpath
//echo "Path: ".$path."\n";
while ($mapvar=readdir($dir)){
if (($mapvar!=".") && ($mapvar!="..")){//is valid var
if (is_dir($path."/".$mapvar)){//is(are) dir(s)
//echo "dir: ".$mapvar."\n";
$this->setArrayValue($dirmap, $pathlevel,$mapvar);
$this->buildmap($path."/".$mapvar);//scan subdir
}
else {//is(are) file(s)
//echo "file: ".$mapvar."\n";
$this->setArrayValue($dirmap, $pathlevel,$mapvar);
}
}
}
closedir($dir);
}
}//end class