Jump to content

Getting rid of white space in an array


skippt
Go to solution Solved by QuickOldCar,

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

Link to comment
Share on other sites

  • Solution

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.

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.