note 100354 deleted from book.array by danbrown
| From: | danbrown@php.net | Date: | Sun, 10 Oct 2010 23:28:47 +0000 |
| Subject: | note 100354 deleted from book.array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173122@lists.php.net to get a copy of this message | ||
Note Submitter: joseph dot davidson dot 707 at gmail dot com
----
A couple of functions (could be one) that will search a Multi-Dimensional array no matter the size
and operate on all of it's elements.
function dCount($mdArray) {
//*
$baseType = gettype($mdArray);
//*
if($baseType == 'array') {
//*
$count = 0;
//*
$type = $baseType;
//*
while($type == 'array') {
//*
$mdArray = current($mdArray);
$type = gettype($mdArray);
$count++;
//*
}
//*
}
else return false;
//*///
return $count;
//*///
}
function mdArray($array) {
$baseType = gettype($array);
$baseCount = count($array);
//print 'BaseCount: ' . $baseCount . '<br>';
for($x = 0; $x < $baseCount; $x++) {
//*
if(gettype(current($array)) == 'array') {
//*
$drop = current($array);
//*
$dCount = $this->dCount($drop);
//*
$count = count($drop);
//print '<br>' . $dCount . ' * ' . $count . '<br>';
//*
for($z = 0; $z < $dCount; $z++) {
//*
if(gettype(current($drop)) !== 'array') {
//*
$count = count($drop);
//*
for($y = 0; $y < $count; $y++) {
//*CODE HERE -------------------------***
print current($drop) . '/';
//*
next($drop);
//*
}
//*
print '<br>';
//*
}
$drop = reset($drop);
//*
}
//*
}
else print 'Not Multidimensional';
//*
next($array);
//*
}
//*
}