Garayed.com  

Go Back   Garayed.com > PHP
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-2006, 10:33 AM
Sonnich
 
Posts: n/a
Default truncating an array

Hi all!

I have 2 arrays of parts and assemblies. I check the part array whether
there is an assembly part in there, if so, 1) it should be moved to
the assembly array 2) its parts should be added to the parts array 3)
it should be removed from the parts array.

My problem is to delete from the assy array, ot truncate it. I am used
to Delphi, where the is a SetLenght function.

Code;

$j=count($part1)-1; // counting down is faster than counting up
while( ($j>=0) && !($part1[$j] == $CurrentItem]) )
$j--;
if($j>-1)
{
// move to assy
$assy1[]=$part1[$j];
// clear up array
while($j < count($part1)-2)
{
$part1[$j]=$part1[$j+1];
$j++;
}
// free last item
unset($part1[$j]);

This moves it all, but the unset does not remove it (the last one)
from my array.
So I tried this without luck (I dont like to do it this way, but that
was a try):

(when adding parts):

It was as simple as this: $part1[]=odbc_result($result2,1);

Now I tried: (if empty, then reuse)
if( $part1[count($part1)-1] == "" )
{
$part1[count($part1)-1] = odbc_result($result2,1);
}
else
{
$part1[]=odbc_result($result2,1);
}

This instead adds a whole lot more and I end up with a number of items
which I cannot explain and a number of empty items, which are not
overwritten.

Yep, I am still new to arrays in PHP

BR
Sonnich

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:15 PM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.