note 39334 deleted from ref.array by nlopess
| From: | nlopess@php.net | Date: | Sun, 25 Jan 2004 11:33:34 +0000 |
| Subject: | note 39334 deleted from ref.array by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-64131@lists.php.net to get a copy of this message | ||
Note Submitter: Jens
----
This Functions Checks, if a Array or pieces of the Array empty or not. Complete Tutorial is in
German, sry, but i can't spock so good English ;)
<?php
/**
* Diese Funktion überprüft ein ganzes Array auf "vollständigkeit", wobei es drei Arten
der zurückgabe kennt.
*
* 1 : Gibt TRUE bei "unvollständigkeit" zurück und FALSE bei
"vollständigkeit"
* 2 : Gibt die Anzahl der nicht vollständigen Felder zurück sonst 0 bei
"volständigkeit"
* 3 : Legt ein neues Array an, indem alle nicht ausgefüllten Felder als das jeweilige Indiez
* gespeichert sind, bei "vollständigkeit" FALSE
*
* Syntax : CheckArray($ARRAY_VAR, INT ART);
*
* Achtung : Der Standart von ART ist 1, somit muss ART nicht unbedingt angeben werden.
* CheckArray(); gibt TRUE zurück, wenn es sich bei der angebenden Variable nicht
* um ein Array handelt.
*
*/
function CheckArray($array, $art = 1, $i = 0, $ges = 0) {
if(is_array($array)) {
foreach($array as $value) {
if(empty($value)) {
$pos[$i] = $i;
} else {
$ges++;
$pos[$i] = FALSE;
}
$i++;
}
if($art == 1) {
return (count($array) == $ges ? TRUE : FALSE);
} elseif($art == 2) {
$res = count($array) - $ges;
return ($res == 0 ? 0 : $res);
} elseif($art == 3) {
$_ = array();
for($k=0; $k<count($array); $k++) {
if(is_numeric($pos[$k])) {
$_[(count($_) + 1)] = $k;
}
}
return (count($_) == 0 ? FALSE : $_);
}
} else {
return TRUE;
}
}
?>