|
Posted by Rik on 07/13/06 13:53
Sonnich wrote:
> 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
A lot of code, that really doesn't make things clear to me.
Could you give an example of the array you have, and the array(s) you want
to have? That would make things a lot clearer I think.
I mainly don't understand this bit:
2) its parts should be added to the parts array
3) it should be removed from the parts array
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|