array map + class method/function as callback + call_user_func

I don't know what I have done wrong with the code below but it is not working.

if($_data_count = count($_csv_raw_array) > 0){
            foreach($_csv_raw_array as $_csv_row){
                array_push($this->_data, array_map(call_user_func(array($this, 'replace')), $_csv_row));
            }
            return $this->result(true, 'CSV parsing done.', '', $this->_data);
        }

// And the replace function is:

    private function replace($_value){
    return preg_match('/(\r\n|\n|\r)/', $_value) ? '' : $_value;
}

But I don't know why it is not working and throws an exception:

A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Import::replace()

Filename: libraries/Import.php

Line Number: 116

Basically what I wanted to to here is import a CSV file which I already imported, now I want to replace any new line characters that is present within the array to be replaced with empty (nothing). But every time I execute this code it throws an exception. Can you people out there suggest. Please.

Thanx

Answers


As pointed out in the comments, judging by your code you will want to drop that call_user_func, since that is causing the function to be called immediately and that does not seem to be what you want, which I presume is to filter out all the elements within $_csv_row in each iteration:

if($_data_count = count($_csv_raw_array) > 0){
    foreach($_csv_raw_array as $_csv_row){
        array_push($this->_data, array_map(array($this, 'replace'), $_csv_row));
    }
    return $this->result(true, 'CSV parsing done.', '', $this->_data);
}

We can only guess what is your intention though, you might want to provide a sample csv and the desired output so we can understand more precisely what you are looking for if this doesn't solve the problem.


Need Your Help

NETWORK_PROVIDER not Working in android

java android locationmanager

I build app for User to get last location or current location. I use both NETWORK_PROVIDER and GPS_PROVIDER.I have little problem with NETWORK_PROVIDER.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.