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 3 12511
I didnt read all the code below but did you consider using
array_splice() to truncate the array?
$xx=array(1,2,3,5,6);
$yy=array_splice($xx,3);
$yy -(5,6)
$xx-(1,2,3)
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
BR
Sonnich
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
ImOk wrote:
I didnt read all the code below but did you consider using
array_splice() to truncate the array?
$xx=array(1,2,3,5,6);
$yy=array_splice($xx,3);
$yy -(5,6)
$xx-(1,2,3)
ok, this did it for me.
BR
Sonnich This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeremy |
last post by:
I have an include file which has some text such as:
The quick brown fox jumped over the lazy dog
I want to have a certain amount of that text to display on one page
wherein the user can click...
|
by: qazmlp |
last post by:
Can anybody comment(& suggest improvements) on the following
implementation that is for
truncating the character buffer contents to the desired length?
Truncating char array
void...
|
by: VISHNU VARDHAN REDDY UNDYALA |
last post by:
Hello,
Can someone over here help me in truncating a float variable.
I mean if PI=3.14159 ...How can I get to read the first two or first
three decimal values with out rounding them. Any...
|
by: Jitesh Sinha |
last post by:
Hi,
I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal
behaviour of System.Web.mail class. It was truncating the message body
after 3,071 character. The code i was testing...
|
by: DotNetJunkies User |
last post by:
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character. For Example VB 6 is returning a string with the...
|
by: rangermccoy |
last post by:
Hello there,
What are the best php/c libraries for handling media including images,
video, and music?
I would like to manipulate media dfiles, including watermarking,
thumbnailing,...
|
by: Daniel Wilson |
last post by:
We have a stored procedure that is giving us an XML representation (using
FOR XML Explicit) of a sales order. Sometimes that evaluats to quite a long
string. Unfortunately, this XML string is...
|
by: rlrcstr |
last post by:
Is it possible to truncate a MemroyStream to free up the space up to the
current position?
I wantes to be able to just keep dumping bytes into a stream and then read
the stream as needed. After...
|
by: masterofzen |
last post by:
Hi, everybody -- first post for me, though I land here via Google all the time. This is the first time, though, that I just haven't been able to find anything even remotely resembling a solution to...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |