Jump to content

Getting rid of white space in an array


skippt

Recommended Posts

Hi,

 

I'm doing some web scraping and at the end I end up with an array.

$list[] = array('link' => $link, 'types' => $types);

Sometimes name is empty so I end up with an array like this:

Array
(
    [0] => Array
        (
            [link] => 
            [types] => Array
                (
                )

        )

    [1] => Array
        (
            [link] => 
            [types] => Array
                (
                )

       )
    [2] => Array
        (
            [link] => http://example.com
            [types] => Array
                (
                )

        )
)

Is there any way I'd be able to get rid of all the  values that are empty and so each new link starts at key 0?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/284190-getting-rid-of-white-space-in-an-array/
Share on other sites

1) can you serialize the overall array and post that here, so that we can easily reconstruct the array

2) what is "name"? I see no "name" variable or element anywhere.

3) you provided a "before" array dump example (but refer to #1). Can you provide an "after" array dump example? IOW "this is what I have now. This is what I'd like it to look like." IOW don't just describe what you want, show the actual array structure as you want it to end up being.

Loop your array and either unset that result or can create a new array excluding those with blank values for links.

 

Personally i would do checking for when are creating the arrays, maybe you are finding javascript links, maybe need to fix relative links, but obviously is something in your scraping code that should get attention.

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.