Grow your CSS skills. Land your dream job.

Remove specific values from array

  • # July 1, 2013 at 5:02 pm

    My array:

    array (size=15)
    0 =>
    array (size=5)
    ‘title’ => string ‘SCOTUS: No right to remain silence unless you speak up’ (length=54)
    ‘link’ => string ‘http://www.readability.com/read?url=http://www.salon.com/2013/06/30/scotus_no_right_to_remain_silence_unless_you_speak_up_partner/’ (length=130)
    ‘description’ => string ‘This article originally appeared on International Business Times. If you want to invoke your constitutional right to remain silent, you’d better not be silent. That’s the circular logic of a recent…’ (length=209)
    ‘pubDate’ => string ‘Sun, 30 Jun 2013 08:14:59 -0400′ (length=31)
    ‘guid’ => string ‘http://www.readability.com/read?url=http://www.salon.com/2013/06/30/scotus_no_right_to_remain_silence_unless_you_speak_up_partner/’ (length=130)
    1 =>
    array (size=5)
    ‘title’ => string ‘Best Dorm Room Ever! A Peek Inside San Francisco’s New Tiny Apartments’ (length=72)
    ‘link’ => string ‘http://www.readability.com/read?url=http://www.architizer.com/en_us/blog/dyn/91947/best-dorm-rooms-ever-panoramic-interests-smartspace-soma/#.Uc-kbGS9Kc0′ (length=153)
    ‘description’ => string ‘The Berkeley, California-based developer Patrick Kennedy does not like to hear his apartments compared to dorm rooms. “That’s a bad word in our office,” he told Architizer.…’ (length=201)
    ‘pubDate’ => string ‘Sat, 29 Jun 2013 23:24:36 -0400′ (length=31)
    ‘guid’ => string ‘http://www.readability.com/read?url=http://www.architizer.com/en_us/blog/dyn/91947/best-dorm-rooms-ever-panoramic-interests-smartspace-soma/#.Uc-kbGS9Kc0′ (length=153)
    [etc]

    Desired Result:

    array (size=15)
    0 =>
    array (size=5)
    ‘title’ => string ‘SCOTUS: No right to remain silence unless you speak up’ (length=54)
    ‘link’ => string ‘http://www.readability.com/read?url=http://www.salon.com/2013/06/30/scotus_no_right_to_remain_silence_unless_you_speak_up_partner/’ (length=130)
    1 =>
    array (size=5)
    ‘title’ => string ‘Best Dorm Room Ever! A Peek Inside San Francisco’s New Tiny Apartments’ (length=72)
    ‘link’ => string ‘http://www.readability.com/read?url=http://www.architizer.com/en_us/blog/dyn/91947/best-dorm-rooms-ever-panoramic-interests-smartspace-soma/#.Uc-kbGS9Kc0′ (length=153)
    [etc]

    How can I remove `description`, `pubDate` and `guid` from the array so it just leaves `title` and `link`?

    # July 1, 2013 at 5:12 pm

    Instead, wouldn’t you just change the code that iterates through the array to ignore the items that you don’t want?

    # July 1, 2013 at 5:28 pm

    > Instead, wouldn’t you just change the code that iterates through the array to ignore the items that you don’t want?

    I would do that.

    # July 1, 2013 at 5:30 pm

    @TheDoc You mean do something like this?:

    $items = $data; // this is what outputs the 1st example

    $title = $items; // grabs the title
    $url = $items; // grabs the link

    __
    # July 1, 2013 at 5:36 pm

    Ignoring the items you don’t want is usually best.

    _– snip –
    overkill answer._

    # July 1, 2013 at 5:46 pm

    > Ignoring the items you don’t want is usually best.

    @TheDoc, @HugoGiraudel and @traq

    You’re right. I was hoping it would have been more simple than all that. I initially thought it could be done just by using `array_splice()` but I think I’ll stick with ignoring the other strings.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".