AW: [PEAR-DEV] Please have a look at proposed package draft : MultiArray
| From: | Selcuk C. Alan | Date: | Sat, 08 Jan 2005 11:18:34 +0000 |
| Subject: | AW: [PEAR-DEV] Please have a look at proposed package draft : MultiArray | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-35415@lists.php.net to get a copy of this message | ||
Hi,
the class ist working only with 2-dim-arrays correctly. I understand it is a
little confusing with classname "MultiArray" and prefix "ma" in functions.
Indeed the input can be 3-dim or more dimension, but it is not possible (in
the moment) to sort or to filter in this column containing arrays and not
string/int.
Also, there will be errors to use these columns in "maToArray" (as key
column) and in "maGroupBy".
In case, that you don´t use these columns as parameters, the result will
still containing them untouched.
function _args2value()
> If one can write a PHP file with a call to this function with three or
> five arguments, (s)he can as well make an array from these.
You are totally right.
I can kill the function _args2value, and in all functions there are arrays
expected in case of arguments.
Then, for example, it will be possible in "maToArray" to sort and to filter.
(also in maGroupBy)
// {{{ maToArray()
/**
* Generates a 1-dim new array from a 2-dimensional array using given column
names, filter array and sort array
*
* @param array $maInput the 2-dimensional array
* @param string $sCol_value a column name in the array, which will be the
value of the generated result
* @param mixed $sCol_key a column name in the array, which will be the
key of the generated result, false if 0..n will be the key
* @param array $aFilter false for no filtering. array for
filtering
* @param array $aSort false for no sorting. array for sorting
* @return array generated array. ERROR-Object if failed
*
* @access public
* @static
* @since Method available since Release 0.1
*/
function isMultiArray()
> isMultiArray IMHO should be checkArray, because primary function is to
> validate array and not to figure out if array is multidimensional.
ok. Mostly boolean result are expected from "is"-functions. I will change it
next to "checkArray" or something else.
Examples are in the package file "MultiArray.tgz".
Greetings,
Selcuk
"Anatoly Techtonik" <techtonik@php.net> schrieb im Newsbeitrag
news:1859912275.20050107202440@tut.by...
> Hello Selcuk,
>
> Great thing. I prefer to have this among common PHP functions.
> Some picky things from me if you need them, of course. =)
>
>> // {{{ _args2value()
>> /**
>> * Makes an extracted array from mixed input
>> *
>> * @param mixed $mArgument
>> * @param integer $iStart integer of start position
>> *
>> * @return array
>> *
>> * @access private
>> * @static
>> * @since Method available since Release 0.1
>> */
>
>> * Makes an extracted array from mixed input
> Can you describe more populat - what is "extracted array" and why it
> must be "made" and not "extracted"?
>
>> * @param mixed $mArgument
> From this function block I've got an idea what this is some magic function
> which makes array value from some garbage and takes arguments. I can't
> even tell you how to choose a good name for that function, because this
> comment is suitable to more than 50% of functions.
>
> $iStart is useless for me, because it is better to operate with sliced
> input/output than to implement $start, $end, input/output array in one
> function.
>
> My proposal..
>
> // {{{ _makeflat()
> /**
> * Makes a flat (one dimensional array) from mixed input
> *
> * @param mixed $input any, really any
> *
> * @return array
> * @static
> * @since MultiArray-0.0.1
> */
> function _makeflat($input)
> {
> $aResult = array();
>
> $aArg = array_values((array)$input);
> $iCnt = count($aArg);
>
> for ($i=0; $i<$iCnt; $i++) {
> if (is_array($aArg[$i])) {
> $aResult = array_merge($aResult,
> MultiArray::_makeflat($aArg[$i]));
> } else {
> $aResult[] = $aArg[$i];
> }
> }
> return $aResult;
> }
> // }}}
>
>
> Next function IMHO doesn't worth complication. Could you provide a
> working example, where func_get_args() complication will be absolutely
> necessary.
>
>> // {{{ is_multiarray()
> ...
>> if ($argCol !== false) {
>> $aArg = MultiArray::_args2value(func_get_args(), 1);
>> }
> If one can write a PHP file with a call to this function with three or
> five arguments, (s)he can as well make an array from these.
>
> isMultiArray IMHO should be checkArray, because primary function is to
> validate array and not to figure out if array is multidimensional.
>
> Also I'd like to check more complex structures - like presence of some
> fields on specified depth of array. Ideally MA should be easily
> converted to PEAR::Tree and vice versa.
>
>> // {{{ maGroupBy()
>> /**
>> * Set column value of contained multidimensional array as index
>> *
>
> Until there will be tests to show input and output of this function,
> I'm unable to tell how this can be named. Perhaps even something like
> makehashby() - rebuild array using specified field as a key
> NOTE: if duplicated values are found later will be used
>
> BTW, do you have any 3D arrays examples?
> This proposal looks like Array2D =)
>
> php examples will be extremely helpful..
>
> // {{{ maToArray()
> ? make1D()
>
>
> Everything else is ok for now. To tell the truth I just don't have
> enough time. =)
>
> P.S. Idea is great, but it's still Array2D =)
>
>
> SA> Hello everybody,
>
> SA> I want to present you the class "MultiArray". It is a class, which can
> SA> handle multidimensional arrays. See:
> SA>
> SA> http://www.pear.php.net/pepr/pepr-proposal-show.php?id=185
>
> SA> For example it can sort and filter multidimensional arrays using
> several
> SA> parameters, you can see it at work here:
> SA>
>
http://www.scalan.de/home/entwicklung/multiarray/beispiele/10737,10736,1,0.h
tml
>
> SA> Any and all comments and feedback are welcome.
>
>
> SA> Greetings,
>
> SA> Selcuk Alan
>
>
>
>
> t
> --