note 32419 deleted from function.array-splice by felipe
| From: | felipe@php.net | Date: | Sat, 05 Jan 2008 02:08:03 +0000 |
| Subject: | note 32419 deleted from function.array-splice by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134812@lists.php.net to get a copy of this message | ||
Note Submitter: kerxen at caramail dot com
----
<?php
/** **************************
* Document::tableColumn()
*
* { This function sends back a column of the table or the table itself if it has only one column.
* Input : $table, a table at 1 ou 2 dimensions or more
* $numeroCol, the number of the column.
* Output : $output : the column $numero of the table or the table.
* }
*
********** **********/
function tableColumn ( $table, $numeroCol)
{
$output = array();
reset ($table) ;
if (!is_integer($numeroCol)) $numeroCol=0;
if (count($table)==0) return "UNDEFINED";
else { foreach ($table as $ligne) // $ligne est un tableau (si $table est en 2D) ou un string
($table en 1D)
{ if (gettype($ligne)!="array")
{
if (strlen($ligne)!=0) array_push ($output, $ligne) ; // on met le string dans
$output
else array_push ($output, " ") ; // on met une chaine
" " dans $output
}
else
{
if (strlen($ligne[$numeroCol])!=0) array_push ($output, $ligne[$numeroCol]) ; // on
insere la colonne $numero de la ligne dans $output
else array_push ($output, " ") ; //
on met une chaine " " dans $output
}
}
return $output;
}
}
?>
/***************************/
SYNOPTIC : how to use it :
/***************************/
try the exemple below :
<?php
$stack = array ("orange", "banane");
array_push ($stack, "pomme", "bleuet");
$stock = array ($stack,$stack);
print_r ($stock); echo '<br>';
print_r ($stack); echo '<br>';
print_r (tableColumn ($stock,0)) ; echo '<br>';
print_r (tableColumn ($stock,1)) ; echo '<br>';
print_r (tableColumn ($stock,2)) ; echo '<br>';
print_r (tableColumn ($stock,3)) ; echo '<br>';
print_r (tableColumn ($stack,0)) ; echo '<br>';
print_r (tableColumn ($stack,1)) ; echo '<br>';
?>
YOU WILL GET THIS :
Array ( [0] => Array ( [0] => orange [1] => banane [2] => pomme [3] => bleuet ) [1]
=> Array ( [0] => orange [1] => banane [2] => pomme [3] => bleuet ) )
Array ( [0] => orange [1] => banane [2] => pomme [3] => bleuet )
Array ( [0] => orange [1] => orange )
Array ( [0] => banane [1] => banane )
Array ( [0] => pomme [1] => pomme )
Array ( [0] => bleuet [1] => bleuet )
Array ( [0] => orange [1] => banane [2] => pomme [3] => bleuet )
Array ( [0] => orange [1] => banane [2] => pomme [3] => bleuet )
/**************************/
Good Luck
Eddy Cingala