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
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
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
Share on other sites

$str = "";

for ($i = 0; $i < count($file); $i++){

   if ( strlen($file[$i]) > 0 ){  
      $str .= "-" . $file[$i];
   }

}

$str = substr($str, 1);

$file = implode("-", $str);

 

Does that get the desired result?

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.