Jump to content

removing a value from an array


gevans

Recommended Posts

Hey guys,

 

This question isn't really how to do it, as I already have... but I didn't manage to do it the way I wanted to....

 

I have a 'breadcrumb' class that's main method gets passed an array of string. These strings are the different segments of the URI.

 

The whole process is fairly simple, but at the very beginning I check to see if 'home' is in the array, and if so remove it. I'm actually happy with the way I'm currently doing this, but was curious about 'array_filter()'.

 

If I user 'array_filer()' within a class what do I put in the callback place?

 

I thought about doing this (though it didn't really make sense);

 

<?php
class Breadcrumb extends Model {

    function Breadcrumb()
    {
        parent::Model();
    }

    function get(array $values)
    {
        var_dump($values);
        /*$i=0;
        $breadcrumb[$i]['title'] = 'home';
        $breadcrumb[$i]['safe_title'] = 'home';
        $i++;*/
        
        $values = array_filter($values, "$this->breadcrumb->_filter_home");
        
        var_dump($values);
        
        #return $breadcrumb;
    }
    
    function _filter_home($a)
    {
        return ($a === "home")? TRUE : FALSE;
    }
}

 

Was just wondering what you thought?

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.