note 32609 added to function.array-multisort
| From: | fabrice at vignals dot nospam dot com | Date: | Mon, 02 Jun 2003 23:33:37 +0000 |
| Subject: | note 32609 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49588@lists.php.net to get a copy of this message | ||
@ richardNOSPAMneillPLEASE dot org dot uk -- 10-Apr-2003
In some case u must, use multiple dimension array.
In fact, Array is not so hard to manipulated.
I had a problem with : array_multisort();
Warning: Invalid argument supplied for foreach() in g:\_dev\_iware_lib_array.php on line 121
I had this message if I try to use :
$vars = array_multisort( get_defined_vars() ); //beautiful multi level array
foreach ( $vars as $rows => $cols )
{
blalbla php, blabla html
}
so I make something like that, it is a non stress test function, and I am not sure that give the
same result as array_multisort.
Some test must missing
Also this function will display different html output, depending of many options vars (2d table, 2d
table with multirow per value ... )
function IW_Array_Format ($IW_Arr)
{
$i = 1;
// Row Loop
foreach( $IW_Arr as $var => $key )
{
$n = 1;
/*if ( is_int( $var ) && $n =1 ) //
{
array_shift( $IW_Arr );
$n=1;
$i++;
continue;
}
else
{ */ not necessary with foreach
$vars[$i][$n] = $var;
if ( is_array( $key) )
{
foreach ($key as $keys => $keyss )
{
$vars[$i][$n+1] = $keys;
if ( is_array( $keyss ) && $keyss != NULL )
{
$n++;
}
else
{
$vars[$i][$n+2] = ( $keyss === NULL ) ? NULL : $keyss;
$n = 1;
$i++;
}
} // end ... foreach ($key as $keys => $keyss )
}
else
{
$vars[$i][$n+1] = $key;
$n=1;
$i++;
}
// } not necessary with foreach
}
return $vars;
}
/* todo : We must define the number of rows, then use colspan html arg to output a well formated
table */
$vars = <?php IW_Array_Format ( get_defined_vars() ); ?>
<table width="100%" border="0" cellpadding="0"
cellspacing="1">
<?php /* --- START : Repeat Row Region --- Vars Loop ---*/ $vars = IW_Array_Format
($IW_Arr, NULL); $i=1; foreach ( $vars as $row => $col ) { $c =1; ?>
<tr>
<?php /* --- START : Repeat Column Region --- %NAME% ---*/ $c=1; foreach ( $col as $cols )
{ ?>
<td class="<?php echo $class = ($c == 1) ? 'TbInfoRowLabel' :
'TbInfoRow'; ?>"><?php echo $i . '. - ' . $c . ' -- ' .
$cols; ?></td>
<?php /* --- END : Repeat Column Region --- %NAME% ---*/ $c++;} ?>
</tr>
<?php /* --- END : Repeat Row Region --- Vars Loop ---*/ $i++; } ?>
</table>
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32609
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32609&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32609&report=yes