Monday, 27 August 2018
Subscribe to:
Post Comments (Atom)
<?php
$array = array(
'CANON' => array(
'DCIM' => array(
'100CANON',
'101CANON',
'CANONMSC'
),
'CANON_SC' => array(
'IMAGE' => array(
'0001'
),
'DOCUMENT' => array(
'0001'
),
),
'MISC'
));
/CANON/DCIM/100CANON/
/CANON/DCIM/101CANON/
/CANON/DCIM/CANONMSC/
/CANON/CANON_SC/IMAGE/0001/
/CANON/CANON_SC/DOCUMENT/0001/
/CANON/MISC/
<?php
function flatten_directory($array, $prefix = '')
{
$result = '';
foreach($array as $key=>$value)
{
if(is_array($value))
{
$result .= $key .'/'. flatten_directory($value, $prefix . $key . '.');
}
else
{
$result .= $prefix . $key . $value;
}
}
return $result;
}
$result .= $key .'/'. flatten_directory($value, $prefix . $key . '.');
$key
and $value
.function flatten_directory($directory, $prefix = "") {
$result = array();
foreach ($directory as $key => $part) {
if (is_array($part)) {
$result = array_merge($result, flatten_directory($part, $prefix . "/" . $key));
} else {
$result[] = $prefix . "/" . $part . "/";
}
}
return $result;
}
Array
(
[0] => /CANON/DCIM/100CANON/
[1] => /CANON/DCIM/101CANON/
[2] => /CANON/DCIM/CANONMSC/
[3] => /CANON/CANON_SC/IMAGE/0001/
[4] => /CANON/CANON_SC/DOCUMENT/0001/
[5] => /CANON/MISC/
)
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment