Reply to truncating an array

Your name:

Reply:


Posted by Sonnich on 07/13/06 09:33

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация