Re: Not easy! Best way to clean an array of arrays



fluk@xxxxxxx wrote:
Hi Guys, I hope someone can help me with this, because i'm getting
crazy to find a good way to do that!

This is what I got by querying a db.

$arr1 = array("site", "description", "area1" , "activity1");
$arr2 = array("site", "description", "area1" , "activity2");
$arr3 = array("site", "description", "area2" , "activity2");
$arr4 = array("site1", "description1", "area3" , "activity2");

$my_array = array($arr1, $arr2, $arr3, $arr4);

Site and description are linked because they are in the same row of
the same table.
But every site can have 1 or more areas and every area can have 1 or
more activity.

I'd like to clean $my_array in a way I can have a compact one without
doubles

//pseudocode!
$new = array (
array('site','descr') => array (
array('area','activity')
)
);
Is it possible??

Thanks for your precious help
Francesco

Rather I think I'd make both the site name and the area indexes. You can still access the keys of those items, and it will make building your array much easier.

use something like:

$myarray = array($sitename =>
array('description' => $description,
'area' =>
array($area =>'activities' =>
array($activity))));

$sitename is the actual sitename retrieved from the database. This would give you an array similar to

[site1] = Array {
[description] = First site's description
[area] = Array {
[area1] = Array {
[0] = first activity
[1] = second activity
}
}
}


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Not easy! Best way to clean an array of arrays
    ... crazy to find a good way to do that! ... array('site','descr') => array ( ... JDS Computer Training Corp. ...
    (comp.lang.php)
  • Re: Not easy! Best way to clean an array of arrays
    ... crazy to find a good way to do that! ... array('site','descr') => array ( ...
    (comp.lang.php)
  • Re: Shorten Code
    ... Thats really sweet and works great. ... "Dana DeLouis" wrote: ... If you go crazy with too large an array, it can be hard to read and debug. ...
    (microsoft.public.excel.programming)
  • Re: Shorten Code
    ... If you go crazy with too large an array, it can be hard to read and debug. ... cell.HorizontalAlignment = xlCenter ... some of my problem areas that I would like to condense if possible. ...
    (microsoft.public.excel.programming)
  • Re: array and filehandle.
    ... but if the first element of the array is the mode ... any builtin with the function prototype. ... Only perl can parse Perl. ... Looking at code above I've got to crazy conclusion that there are some ...
    (comp.lang.perl.misc)