473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to walk array and delete matched elements?

I'm kind of lost on this one - I need to modify 2 files based on user input:

$data_array = file($data_file);
$counter_array = file($counter_file);
// There is a line-for-line relationship between the data and counter files
//for example, if the 3rd line in the counter file is deleted,
//so also must the 3rd line of the data file be deleted.
// Each line of the data_file has 4 items:
//date|ip_address|user_id|url
for ( $i=0; $i < count($data_array); $i++ )
$data_line = fgets($data_array); //look at each line in data_array
$data = explode("|",$data_line);
if ( $data[1] = $ip ) //$ip is user input
{
array_pop($data_array, $data_line);
array_pop($counter_array[$i];
//not sure array_pop is correct function here - the manual says this
//will pop element from the bottom of the array, but I need
//to delete this particular element from the middle of the array.
//What is the best way to do this?
}

The goal is to create 2 new files. If the original files look like this:

[data_file]
3/4/04|20.123.112.21|grebos|http://www.asc.com
6/5/04|183.40.99.14|boris|http://www.asc.com
7/16/04|133.73.115.29|grebos|http://www.asc.com

[counter file]
2345
1356
5466

and the user selected to remove IP 183.40.99.14, then the new files should
look like this:

[data_file]
3/4/04|20.123.112.21|grebos|http://www.asc.com
7/16/04|133.73.115.29|grebos|http://www.asc.com

[counter file]
2345
5466

I'm still kind of green when it comes to working with arrays... any help is
appreciated... Thanks.
Jul 17 '05 #1
19 3673
deko <ww*******************************@nospam.com> wrote:
I'm kind of lost on this one - I need to modify 2 files based on user input:

8< -- long snip -- >8

<http://de3.php.net/array_splice> should do the job.

--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #2
> <http://de3.php.net/array_splice> should do the job.

Yes, but when the matched element appears twice in a row (that is, in two
lines immediately following each other in datafile.txt), the second one is
not removed from the array. I think this is because the array pointer is
being reset with each loop. Any suggestions on how to correct this?

$data_array = file(datafile.txt);
$counter_file = file(counterfile.txt);
//$ip = user defined

for ( $i=0; $i < count($data_array); $i++ )
{
$data_line = $data_array[$i];
$data = explode("|", $data_line); //data_line format:
date|ip_address|user_id|url
if( in_array($ip, $data) )
{
array_splice($data_array,$i,1);
array_splice($counter_array,$i,1);
}
}
Jul 17 '05 #3
deko <ww*******************************@nospam.com> wrote:
<http://de3.php.net/array_splice> should do the job.


Yes, but when the matched element appears twice in a row (that is, in two
lines immediately following each other in datafile.txt), the second one is
not removed from the array. I think this is because the array pointer is
being reset with each loop. Any suggestions on how to correct this?

$data_array = file(datafile.txt);
$counter_file = file(counterfile.txt);
//$ip = user defined

for ( $i=0; $i < count($data_array); $i++ )
{
$data_line = $data_array[$i];
$data = explode("|", $data_line); //data_line format:
date|ip_address|user_id|url
if( in_array($ip, $data) )
{
array_splice($data_array,$i,1);
array_splice($counter_array,$i,1);
}
}


You mustn't increment after removing an element:

if x == 'b' || x == 'c' -> remove:

i=0.
A B C D E
^-- not removed, i->1

i=1
A B C D E
^-- remove, i->2, data->A C D E

i=2
A C D E
^-- oops, missed the one which fills the hole the previosly deleted
element left...

--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #4
"deko" <ww*******************************@nospam.com> wrote in message
news:bG***************@newssvr13.news.prodigy.com. ..
I'm kind of lost on this one - I need to modify 2 files based on user input:
$data_array = file($data_file);
$counter_array = file($counter_file);
// There is a line-for-line relationship between the data and counter files //for example, if the 3rd line in the counter file is deleted,
//so also must the 3rd line of the data file be deleted.
// Each line of the data_file has 4 items:
//date|ip_address|user_id|url
for ( $i=0; $i < count($data_array); $i++ )
$data_line = fgets($data_array); //look at each line in data_array
$data = explode("|",$data_line);
if ( $data[1] = $ip ) //$ip is user input
{
array_pop($data_array, $data_line);
array_pop($counter_array[$i];
//not sure array_pop is correct function here - the manual says this
//will pop element from the bottom of the array, but I need
//to delete this particular element from the middle of the array.
//What is the best way to do this?
}

The goal is to create 2 new files. If the original files look like this:

[data_file]
3/4/04|20.123.112.21|grebos|http://www.asc.com
6/5/04|183.40.99.14|boris|http://www.asc.com
7/16/04|133.73.115.29|grebos|http://www.asc.com

[counter file]
2345
1356
5466

and the user selected to remove IP 183.40.99.14, then the new files should
look like this:

[data_file]
3/4/04|20.123.112.21|grebos|http://www.asc.com
7/16/04|133.73.115.29|grebos|http://www.asc.com

[counter file]
2345
5466

I'm still kind of green when it comes to working with arrays... any help is appreciated... Thanks.


The function you need is array_filter().
Jul 17 '05 #5
> The function you need is array_filter().

Well, I came up with the below code which is kind of a brute force way to do
it - but it works.
I looked up array_filter in the manual - perhaps it could be used in place
of the first if statement?

<?php
$data_file = "/path/to/data.txt";
$counter_file = "/path/to/counter.txt";
//need to reverse arrays because files are not the same length
//but there is a line-to-line relationship starting from the bottom
$data_array_ascending = file($data_file);
$data_array = array_reverse($data_array_ascending);
$counter_array_ascending = file($counter_file);
$counter_array = array_reverse($counter_array_ascending);
$d = count($data_array);
echo $d." elements in data_array log\n\n";
$ip = "68.122.35.157";
while ( $d > $e )
{
$d = count($data_array);
for ( $i=0; $i < count($data_array); $i++ )
{
$data_line = $data_array[$i];
$data = explode("|", $data_line);
//each line of data.txt has several elements separated by "|"
if( in_array($ip, $data) )
{
array_splice($data_array,$i,1);
array_splice($counter_array,$i,1);
$c++;
$removed = $data_line.$removed;
}
}
$e = count($data_array);
if ( $removed && $d == $e )
{
echo $c." elements removed:\n\n".$removed."\n\n";
}
}
echo $e." elements in data_array\n\n";
$data_array_scrubbed = array_reverse($data_array);
$fp = fopen($data_file,"w");
foreach($data_array_scrubbed as $var)
{
fwrite($fp, $var);
}
fclose($fp);
$counter_array_scrubbed = array_reverse($counter_array);
$fp = fopen($counter_file,"w");
foreach($counter_array_scrubbed as $var)
{
fwrite($fp, $var);
}
fclose($fp);
?>
Jul 17 '05 #6
"deko" <ww*******************************@nospam.com> wrote in message
news:%t****************@newssvr13.news.prodigy.com ...
The function you need is array_filter().
Well, I came up with the below code which is kind of a brute force way to

do it - but it works.
I looked up array_filter in the manual - perhaps it could be used in place
of the first if statement?


What I would do is this: Pass both arrays to array_map(), with null as the
callback function. You will end up with an array with the following
structure:

Array
(
[0] => Array
(
[0] => 3/4/04|20.123.112.21|grebos|http://www.asc.com
[1] => 2345
)

[1] => Array
(
[0] => 6/5/04|183.40.99.14|boris|http://www.asc.com
[1] => 5466
)
)

Write a function that decides whether an element should be removed. It'll
need to get the IP address via a global variable because array_filter()
doesn't let you pass data to the callback. Or if you want to be more
elegant, define a lamda function with create_function() that looks for that
specific IP. Anyway, the function would look something like this:

function NotMatchIP($a) {
global $ip;
$data_line = $a[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}

Pass the combined array to array_filter() using this function as the
callback. The array returned will contain the scrubbed content for both
files. Just loop through it and write to both at the same time.

The trick here is the use of array_map(). Working with one array is
obviously easier than two.
Jul 17 '05 #7
> What I would do is this: Pass both arrays to array_map(), with null as the
callback function. You will end up with an array with the following
structure:

Array
(
[0] => Array
(
[0] => 3/4/04|20.123.112.21|grebos|http://www.asc.com
[1] => 2345
)

[1] => Array
(
[0] => 6/5/04|183.40.99.14|boris|http://www.asc.com
[1] => 5466
)
)
So, this is a multi-dimensional array, correct?
Write a function that decides whether an element should be removed. It'll
need to get the IP address via a global variable because array_filter()
doesn't let you pass data to the callback. Or if you want to be more
elegant, define a lamda function with create_function() that looks for that specific IP. Anyway, the function would look something like this:

function NotMatchIP($a) {
global $ip;
$data_line = $a[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}
is this a lamda function? What is a lamda function?

Pass the combined array to array_filter() using this function as the
callback. The array returned will contain the scrubbed content for both
files. Just loop through it and write to both at the same time.
This sounds interesting - I'll give it a shot.
The trick here is the use of array_map(). Working with one array is
obviously easier than two.

Jul 17 '05 #8
deko <ww*******************************@nospam.com> wrote:
What I would do is this: Pass both arrays to array_map(), with null as the
callback function. You will end up with an array with the following
structure:

Array
(
[0] => Array
(
[0] => 3/4/04|20.123.112.21|grebos|http://www.asc.com
[1] => 2345
)

[1] => Array
(
[0] => 6/5/04|183.40.99.14|boris|http://www.asc.com
[1] => 5466
)
)


So, this is a multi-dimensional array, correct?


Correct.
Write a function that decides whether an element should be removed. It'll
need to get the IP address via a global variable because array_filter()
doesn't let you pass data to the callback. Or if you want to be more
elegant, define a lamda function with create_function() that looks for
that specific IP. Anyway, the function would look something like this:

function NotMatchIP($a) {
global $ip;
$data_line = $a[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}


is this a lamda function? What is a lamda function?


No. As soon as you use the control word "function" you have a named
function (here: NotMatchIP). A lambda function is an unnamed function,
created by create_function() and *only* by create_function().
While you can call a named function using it's name (here:
MotMatchIp($foo)), you can't call a lambda function the same way, since it
has no name. Instead, you have a variable containing the function, calling
the variable with your parameters:
-----BEGIN PHP CODE BLOCK-----
$my_unnamed_function = create_function('$x','echo $x+1;');
$my_unnamed_function(5); // outputs 6. notice the preceding dollar sign
$echo_next_integer = $my_unnamed_function;
$echo_next_integer(17); // outputs 18.
------END PHP CODE BLOCK------

I am not sure about this, but I guess, that internally the concept of PHPs
"function pointers" is used, like in:
-----BEGIN PHP CODE BLOCK-----
$trigonomical_function = 'sin'; // string!
echo $trigonomical_function($x); // calls sin($x)
------END PHP CODE BLOCK------
Therefore echo $my_unnamed_function should give you the internally used
name of the function. (Which is of no use, since it might change from one
parsing of the script to the next... It's just a technical detail.)

As you can see, you can "copy" the function to another variable, so you
could create whole bunches of functions, saving them in an array and
applying them one after another. All you have to do is to define a API of
parameters which will be used and returned:
-----BEGIN PHP CODE BLOCK-----
// define a function
function square($x) {
return $x*$x;
}

// list functions to use
$funcs = array(
'sin', // internal function
'square', // user-defined function
create_function('$x','return $x*2') // lambda function
);

// output results
foreach ($funcs as $funcname)
echo $funcname . '(10) is: ' . $funcname(10) . chr(13);
------END PHP CODE BLOCK------
(Note: Every of these functions takes exactly one number.)

HTH
Simon
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #9
> > is this a lamda function? What is a lamda function?

No. As soon as you use the control word "function" you have a named
function (here: NotMatchIP). A lambda function is an unnamed function,
created by create_function() and *only* by create_function().
While you can call a named function using it's name (here:
MotMatchIp($foo)), you can't call a lambda function the same way, since it
has no name. Instead, you have a variable containing the function, calling
the variable with your parameters: .... snip ... I am not sure about this, but I guess, that internally the concept of PHPs
"function pointers" is used, like in: .... snip ... Therefore echo $my_unnamed_function should give you the internally used
name of the function. (Which is of no use, since it might change from one
parsing of the script to the next... It's just a technical detail.)

As you can see, you can "copy" the function to another variable, so you
could create whole bunches of functions, saving them in an array and
applying them one after another. All you have to do is to define a API of
parameters which will be used and returned:


Thanks for the info - I appreciate the feedback.

The problem with using a multi-dimensional array is that the 2 files are
different lengths. I need to create both arrays individually to do stuff in
an earlier section of the script, so it's easy enough to reverse them and
start from the bottom. As long as the array keys stay in sync, it should
work...

$data_array_r = array_reverse($data_array);
$counter_array_r = array_reverse($counter_array);
$d = count($data_array_r) - 1; // there's a reason for -1
echo "Starting with ".$d." entries<br><br>";
while ( $d > $s )
// $d>$s causes the while loop
//to run at least twice - so if there
//are 2 entries in a row in data_array
//that need to be spliced out,
//the second one isn't missed
//due to the array pointer reseting
//with each for loop.
{
$d = count($data_array_r) - 1;
for ( $i=0; $i < $d; $i++ )
{
$data_line = $data_array_r[$i];
$data = explode("|", $data_line);
if( in_array($ip, $data) )
{
// here's where the 2 in a row problem arises
array_splice($data_array_r,$i,1);
array_splice($counter_array_r,$i,1);
$n++;
$removed = $data_line."<br>".$removed;
}
}
$s = count($data_array_r) - 1;
if ( $removed && $d == $s )
{
echo $n." entries removed:<br><br>".$removed."<br>";
}
}
echo "Ending with ".$s." entries<br>";
Jul 17 '05 #10
"deko" <ww*******************************@nospam.com> wrote in message
news:3g****************@newssvr13.news.prodigy.com ...
The problem with using a multi-dimensional array is that the 2 files are
different lengths. I need to create both arrays individually to do stuff in an earlier section of the script, so it's easy enough to reverse them and
start from the bottom. As long as the array keys stay in sync, it should
work...


There is no problem at all. If the one array is shorter than the other,
array_map() would just leave the corresponding element null. It's easy
enough to check for null before writing out a line.
Jul 17 '05 #11
> There is no problem at all. If the one array is shorter than the other,
array_map() would just leave the corresponding element null. It's easy
enough to check for null before writing out a line.


Let's give this a shot - so I have 2 different length arrays that are mapped
(lets' call them c and d) and there is an element-to-element relationship
between the arrays. I need to walk through each element of array d,
exploding each element into another array (let's call it e) and check for a
particular value in e - if there's a match, I need to splice that element
out of both d and c. When this is done, I need to write out each array to a
separate file. Note that the d will have hundreds of elements, while c will
have thousands. The files from which the arrays are built are in ascending
order, but the-element to-element relationship starts at the bottom of the
files - so, for example, element 0 - 300 in d will map to 4000 - 4300 in c.

Okay, so first map the arrays:

$array_map = array_map(null, $c, $d)

Then, as suggested earlier, use a function to look for the element in
question in e (here's where I'm lost)

function findIp($???)
{
???
}

then use this function in a for loop?

foreach ( $d as $var )
{
findIp($???)
)

then write out each array

$fpc = fopen($data_file, "w")'
$fpd = fopen($counter_file, "w")
foreach($array_map as ???)
{
fwrite($fpc, ???)
fwrite($fpd, ???)
}
fclose($fpc)
fclose($fpd)

how to use foreach with a multi-dimensional array???

Jul 17 '05 #12
I think this is close, but I get the following errors:

Warning: array_filter(): The second argument, '', should be a valid callback
in /test.php on line 84

Warning: Invalid argument supplied for foreach() in /test.php on line 89

Warning: Invalid argument supplied for foreach() in /test.php on line 94

if ( $ip )
{
$da = count($data_array) - 1;
echo "Starting with ".$da." entries<br><br>";
function noMatch($mapped_array)
{
global $ip;
$data_line = $mapped_array[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}
$mapped_array = array_map(null, $data_array, $counter_array);
$array_scrub = array_filter($mapped_array, $noMatch); // line 84 *****
$sa = count($array_scrub[0] - 1);
echo "Ending with ".$sa." entries<br><br>";
$fpd = fopen($data_file, "w");
$fpc = fopen($counter_file, "w");
foreach ( $array_scrub[0] as $d ) // line 89 *****
{
fwrite($d, $fpd);
}
fclose($fpd);
foreach ( $array_scrub[1] as $c ) // line 94 *****
{
fwrite($c, $fpc);
}
fclose($fpc);
unset($ip);
}
Jul 17 '05 #13
Using "matchIp" rather than "noMatch" - no errors, but results are incorrect

//----- code -----//

$da = count($data_array);
echo "Starting with ".$da." entries<br><br>";
function matchIp($mapped_array)
{
global $ip;
$data_line = $mapped_array[0];
$data = explode("|", $data_line);
return ($ip = $data[1]); //<<==== ** note change here **
}
$mapped_array = array_map(null, $data_array, $counter_array);
$array_scrub = array_filter($mapped_array, "matchIp");
$sa = count($array_scrub);
echo "Ending with ".$sa." entries<br><br>";

//----- output -----//

Starting with 148 entries

Ending with 148 entries
Jul 17 '05 #14
Not sure how to use the callback function. Also, how do I reference one
part of a multi-dimensional array?

//----- code -----//

echo "Starting with ".count($data_array)." entries<br><br>";
function ipFilter($mapped_array)
{
global $ip;
foreach ($mapped_array as $data_line)
{
$data_line = $mapped_array[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}
}
$mapped_array = array_map(null, $data_array, $counter_array);
$array_scrub = array_filter($mapped_array, "ipFilter");
echo "Ending with ".count($data_array)." entries<br><br>";

//----- output -----//

Starting with 148 entries

Ending with 148 entries ====>> this should be 1 less than starting number
Jul 17 '05 #15
Perhaps the problem is with the function. What's happening, I think, is the
entire array (that is, $mapped_array[0]) is being exploded, not just each
individual line. Therefore, only the first and last elements of the array
don't match $ip. Furthermore, the null values beginning at [148] do not
match $ip. This results in the corresponding elements in $mapped_array[1]
being filtered out, reducing it also to 2 elements. The correct output
should look like this:

Starting with 148 elements in data_array
Starting with 4262 elements in counter_array

Ending with 147 elements in data_array
Ending with 4261 elements in counter_array

//----- code -----//

echo "Starting with ".count($data_array)." elements in data_array<br>";
echo "Starting with ".count($counter_array)." elements in
counter_array<br><br>";
function ipFilter($mapped_array)
{
global $ip;
$data_line = $mapped_array[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}
$mapped_array = array_map(null, $data_array, $counter_array);
$scrubbed_array = array_filter($mapped_array, "ipFilter");
echo "Ending with ".count($scrubbed_array[0])." elements in
data_array<br>";
echo "Ending with ".count($scrubbed_array[1])." elements in
counter_array<br><br>";

//----- output -----//

Starting with 148 elements in data_array
Starting with 4262 elements in counter_array

Ending with 2 elements in data_array
Ending with 2 elements in counter_array

The files look like this:

[data_file]
3/4/04|20.123.112.21|grebos|http://www.abc.com
6/5/04|183.40.99.14|boris|http://www.def.com
7/16/04|133.73.115.29|grebos|http://www.ghi.com
....

[counter_file]
2345
1356
5466
....
Jul 17 '05 #16
here's another attempt -

$mapped_array = array_map(null, $data_array, $counter_array);
for ( $i=count($mapped_array[0]; $i > 0; $i-- )
{
$data_line = $mapped_array[0][$i];
$data = explode("|", $data_line);
if( in_array($ip, $data) )
{
array_splice($mapped_array,$i,1);
}
}

not sure how to work with multidimensional arrays...
Jul 17 '05 #17
"deko" <ww*******************************@nospam.com> wrote in message
news:0U*****************@newssvr14.news.prodigy.co m...
Not sure how to use the callback function. Also, how do I reference one
part of a multi-dimensional array?


array_filter() will pass each element of an array. In this case the element
is a one-dimension array. Here's how the code should look. Tested and seemed
to work.

<?

$counter = file("counter.txt");
$data = file("data.txt");
$counter_a = array_reverse($counter);
$data_a = array_reverse($data);

$data_counter_a = array_map(null, $data_a, $counter_a);

function ipFilter($a) {
global $ip;
$data_line = $a[0];
$data = explode('|', $data_line);
return ($data[1] != $ip);
}

$ip = '20.123.112.21'; // or whatever

$data_counter_a = array_filter($data_counter_a, 'ipFilter');
$data_counter = array_reverse($data_counter_a);

$f1 = fopen("counter_new.txt", "w");
$f2 = fopen("data_new.txt", "w");

foreach($data_counter as $a) {
list($data, $counter) = $a;
if($counter) {
fwrite($f1, "$counter");
}
if($data) {
fwrite($f2, "$data");
}
}

fclose($f1);
fclose($f2);

?>
Jul 17 '05 #18
> $counter = file("counter.txt");
$data = file("data.txt");
$counter_a = array_reverse($counter);
$data_a = array_reverse($data);

$data_counter_a = array_map(null, $data_a, $counter_a);

//what's this function is doing (I think) is receiving the
//array $data_counter_a (as $a). But what is it doing
//with it? Isn't data_line = $a[0] just reading in the first line
//of data_counter_a? How does it loop through each element? function ipFilter($a) {
global $ip;
$data_line = $a[0];
$data = explode('|', $data_line);
return ($data[1] != $ip);
}

$ip = '20.123.112.21'; // or whatever

$data_counter_a = array_filter($data_counter_a, 'ipFilter');
$data_counter = array_reverse($data_counter_a);

$f1 = fopen("counter_new.txt", "w");
$f2 = fopen("data_new.txt", "w");

foreach($data_counter as $a) { //not sure what's happening here list($data, $counter) = $a; //I assume the if statements are supposed to remove blanks if($counter) {
fwrite($f1, "$counter");
}
if($data) {
fwrite($f2, "$data");
}
}

fclose($f1);
fclose($f2);

?>

Jul 17 '05 #19
> array_filter() will pass each element of an array. In this case the
element
is a one-dimension array. Here's how the code should look. Tested and seemed to work.


Hey! - I think this is working (I changed the variable names to be more
intuitive - at least for me).

Questions:

Why the strange Ending output:

Starting with 142 entries
Ending with 142.0908 entries <<== ??

How can $baz not be an integer value?

I still don't understand how that function works. How does "$data_line =
$foo[0]" loop through all elements in the array? Is that just how
array_filter works?

Also, I'm still unsure what "list($data_item, $counter_item) = $bar" does.
The manual was not much help.

Thanks again for help!

//----- code -----//
if ( $ip )
{
$data_array = file($data_file);
$counter_array = file($counter_file);
$data_array_r = array_reverse($data_array);
$counter_array_r = array_reverse($counter_array);
$mapped_array = array_map(null, $data_array_r, $counter_array_r);
$da = count($data_array_r);
echo "Starting with ".$da." entries<br><br>";
function ipFilter($foo)
{
global $ip;
$data_line = $foo[0];
$data = explode('|', $data_line);
return ($data[1] != $ip);
}
$mapped_array = array_filter($mapped_array, 'ipFilter');
$mapped_array_scrubbed = array_reverse($mapped_array);
$fd = fopen($data_file, "w");
$fc = fopen($counter_file, "w");
foreach ($mapped_array_scrubbed as $bar)
{
list($data_item, $counter_item) = $bar;
if ($data_item)
{
fwrite($fd, $data_item);
$baz++;
}
if ($counter_item)
{
fwrite($fc, $counter_item);
}
}
fclose($fd);
fclose($fc);
echo "Ending with ".$baz." entries<br><br>";
}
/*
//----- output -----//
Starting with 142 entries
Ending with 142.0908 entries
*/
Jul 17 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
18
by: Dan | last post by:
hello, I would to know if it is possible to delete an instance in an array, The following does not allow me to do a delete. I am trying to find and delete the duplicate in an array, thanks ...
13
by: J. J. Cale | last post by:
I have the following. There must be something less cumbersome without push pop. The function parameter obj is the event.srcElement and has the attributes(properties?) picNum and alb pinned to it....
5
by: effendi | last post by:
I wrote a simple script to remove an element of an array but I don't think this is the best way to go about it. I have a list of about five elements seperated by ";" I split the array using...
3
by: Newcomsas | last post by:
Hello, I'm trying to solve a problem with JS textbox array without success. I have two buttons in my page: PLUS and MINUS; at every click on PLUS a new textbox named 'dear' is generated. So, if...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.