Jump to content

[SOLVED] Little help.


unkwntech

Recommended Posts

I'm beating my head against the desk with this one.

I have an array, the end of the array looks like this:

    [2389] => 127.0.0.1 zanox.com
    [2390] => 127.0.0.1 zeads.com
    [2391] => 127.0.0.1 zedo.com
    [2392] => 127.0.0.1 zencudo.co.uk
    [2393] => 127.0.0.1 zenzuu.com
    [2394] => 127.0.0.1 zeus.developershed.com
    [2395] => 127.0.0.1 zintext.com
    [2396] => 127.0.0.1 zmedia.com
    [2397] => 
    [2398] => 
    [2399] => 
    [2400] => 
    [2401] => 
    [2402] => 
    [2403] =>

I have this code, that is processing the array before it is outputted:

for($i=0;$i<count($file);$i++)
{
if(strlen($file[$i]) < 1)
 {
	unset($file[$i]);
 }
}

If I echo strlen($file[2403]) I get zero, but obviously the above loop should be removing it.

Link to comment
https://forums.phpfreaks.com/topic/127663-solved-little-help/
Share on other sites

I'm beating my head against the desk with this one.

I have an array, the end of the array looks like this:

    [2389] => 127.0.0.1 zanox.com
    [2390] => 127.0.0.1 zeads.com
    [2391] => 127.0.0.1 zedo.com
    [2392] => 127.0.0.1 zencudo.co.uk
    [2393] => 127.0.0.1 zenzuu.com
    [2394] => 127.0.0.1 zeus.developershed.com
    [2395] => 127.0.0.1 zintext.com
    [2396] => 127.0.0.1 zmedia.com
    [2397] => 
    [2398] => 
    [2399] => 
    [2400] => 
    [2401] => 
    [2402] => 
    [2403] =>

I have this code, that is processing the array before it is outputted:

for($i=0;$i<count($file);$i++) /*???*/
{
   if(strlen($file[$i]) < 1)
    {
      unset($file[$i]);
    }
}

If I echo strlen($file[2403]) I get zero, but obviously the above loop should be removing it.

Link to comment
https://forums.phpfreaks.com/topic/127663-solved-little-help/#findComment-660722
Share on other sites

@Andy-H:

The following:

<?php
$array = range(0, 100000);
$start1 = microtime(TRUE);
for($i=0;$i<count($array);$i++)
{
	//do something
}
$time1 = microtime(TRUE) - $start1;
$start2 = microtime(TRUE);
$count = count($array);
for($i=0;$i<$count;$i++)
{
//do something
}
$time2 = microtime(TRUE) - $start2;
echo 'Time 1: ' . $time1 . ' Time 2: ' . $time2;
?>

outputs the following on my system:

Time 1: 0.82814311981201 Time 2: 0.84739398956299

So indeed my way was faster.  I don't mean this to be argumentative, I just wanted to verify what you said and these are the results.

 

Link to comment
https://forums.phpfreaks.com/topic/127663-solved-little-help/#findComment-660725
Share on other sites

Why not something like this?

 

$array = array("127.0.0.1 zanox.com",
	"127.0.0.1 zeads.com",
	"127.0.0.1 zedo.com",
	"127.0.0.1 zencudo.co.uk",
	"127.0.0.1 zenzuu.com",
	"127.0.0.1 zeus.developershed.com",
	"127.0.0.1 zintext.com",
	"127.0.0.1 zmedia.com",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
);

$tmp_array = array();
for($i = 0; $i < count($array); $i++){
if($array[$i] != ""){
	$tmp_array[$i] = $array[$i];
}
}
$array = $tmp_array;

echo "<pre>", print_r($array), "</pre>";

Link to comment
https://forums.phpfreaks.com/topic/127663-solved-little-help/#findComment-660763
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.