note 100354 added to book.array
| From: | joseph dot davidson dot 707 at gmail dot com | Date: | Sun, 10 Oct 2010 22:28:19 +0000 |
| Subject: | note 100354 added to book.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173120@lists.php.net to get a copy of this message | ||
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);
//*
}
//*
}
----
Server IP: 208.69.120.55
Probable Submitter: 67.174.228.162
----
Manual Page -- http://www.php.net/manual/en/book.array.php
Edit -- https://master.php.net/note/edit/100354
Del: integrated -- https://master.php.net/note/delete/100354/integrated
Del: useless -- https://master.php.net/note/delete/100354/useless
Del: bad code -- https://master.php.net/note/delete/100354/bad+code
Del: spam -- https://master.php.net/note/delete/100354/spam
Del: non-english -- https://master.php.net/note/delete/100354/non-english
Del: in docs -- https://master.php.net/note/delete/100354/in+docs
Del: other reasons-- https://master.php.net/note/delete/100354
Reject -- https://master.php.net/note/reject/100354
Search -- https://master.php.net/manage/user-notes.php