php - get parent array name after array_walk_recursive function -
i use following function verify if search word in name of files of folder.
$files2=list_files("documents/minelli"); class commentaire_filter{ static function test_print($item, $key, $value) { if (preg_match("#".$value."#", $item)) { $array = array($key=>$item); print_r($array); ?> <a href="documents/minelli/<?php echo $item; ?>"><?php echo $key.' '. $item; ?></a><br /> <?php } } } array_walk_recursive($files2, 'commentaire_filter::test_print',$motrecherche );
i obtain list of files.
i add link permit users download file.
when i'm using array_walk_recursive function, can name of file , key. how can name of parent arrays made link ?
here extract of $files:
array (size=5)
'administratifs' =>
array (size=5) 0 => string 'campagne-sanmarina.jpg' (length=22) 1 => string 'cosmo echantillons ete 2009.xls' (length=31) 2 => string 'cosmoparis echantillons maro hiver 2011 311-411.xls' (length=51) 3 => string 'cosmoparis-boutique.jpg' (length=23) 4 => string 'minelli-20-ans.png' (length=18)
'commerce' =>
array (size=4) 0 => string 'a-gagner-cosmoparis.jpg' (length=23) 1 => string 'controle 2009.pdf' (length=17) 2 => string 'cosmoparis-boutique.jpg' (length=23) 3 => string 'soldes-cosmoparis.jpg' (length=21)
'gestion' =>
array (size=1) 'procedures' => array (size=5) 0 => string 'cosmoparis-boutique.jpg' (length=23) 1 => string 'flux-ecommerce-smc.pdf' (length=22) 2 => string 'minelli-lyon.jpg' (length=16) 3 => string 'sanmarina-magasin-interieur.jpg' (length=31) 4 => string 'visuel_chaussures_minelli_printemps_ete_2009.jpg' (length=48)
'magasins' =>
array (size=2) 0 => string 'cosmo echantillons ete 2009.xls' (length=31) 1 => string 'san-marina-saint-etienne.jpg' (length=28)
'ressources humaines' =>
array (size=7) 'actualites paye' => array (size=3) 0 => string 'cosmoparis echantillons maro hiver 2011 311-411.xls' (length=51) 1 => string 'cosmoparis-boutique25.jpg' (length=23) 2 => string 'minelli-tours.jpg' (length=17) ...
for 'cosmoparis-boutique25.jpg', parent array name ('ressources humaines'=>'actualites paye'). how can information build link 'myfolder/ressources humaines/actualites paye/cosmoparis-boutique25.jpg ?
thank help!
you have ditch array_walk_recursive
, roll own recursive walk. allow maintain or pass custom state information whenever recurse.
for example:
function my_walk_recursive(array $array, $path = null) { foreach ($array $k => $v) { if (!is_array($v)) { // leaf node (file) -- print link $fullpath = $path.$v; // whatever want $fullpath, e.g.: echo "link $fullpath\n"; } else { // directory node -- recurse my_walk_recursive($v, $path.'/'.$k); } } }
Comments
Post a Comment