note 34577 added to function.array-values
| From: | max at rack1 dot php dot net | Date: | Thu, 31 Jul 2003 08:56:38 +0000 |
| Subject: | note 34577 added to function.array-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53052@lists.php.net to get a copy of this message | ||
I have this to reindex an array. In this case one, two o three values in array $dates is =0 or
="", but I don't know which and how many are. If are two values = 0 the array
$add_dates contains two elements, If are three values = 0 so
$add_dates contains three too. This is because I need 4 elements with values != 0 to put inside the
buttons at the end //the buttons show nothing if the value is 0. So, to create just 4 buttons first
I need filter the empty keys, but with this the keys are not reindex and I don't know how can
I do to reference them. For that array_values() is perfect.
Sorry for my english 8)
//translate ;)
Para reindexar los valores de un array desde 0. En este caso uno o más valores del array $dates son
iguales a cero o = "", pero no se puede determinar cuántos ni cuáles son. Si son dos
valores = 0, el array $add_dates contiene 2 elementos, si son tres, $add_dates contiene tres
también. Esto porque al final necesito 4 elementos diferentes de cero para crear cuatro botones
//los botones muestran nada si les asigno valores vacíos. Entonces para crear solo cuatro botones
primero filtro las claves con valores vacíos, pero al hacerlo los valores restantes mantienen sus
claves y no se sabe como referenciarlos. Para eso reindexo todo con arrays_values().
function take_out($var) {
if($var=="" or $var==0){
}
else{
$newvar=$var;
}
return $newvar;
}
$dates = array ($exp1,$exp2,$exp3,$exp4);
$all_dates = array_merge($dates,$add_dates);
$semi_final_dates = array_filter($all_dates, "take_out");
$final_dates= array_values($semi_final_dates);
echo "<input type='button' name='exp' value='$final_dates[0]'
class=input>";
echo "<input type='button' name='exp' value='$final_dates[1]'
class=input>";
echo "<input type='button' name='exp' value='$final_dates[2]'
class=input>";
echo "<input type='button' name='exp' value='$final_dates[3]'
class=input>";
----
Manual Page -- http://www.php.net/manual/en/function.array-values.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34577
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34577&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34577&report=yes