array_map not working in classes array_map not working in classes arrays arrays

array_map not working in classes


You are specifying dash as the callback in the wrong way.

This does not work:

$this->classarray = array_map($this->dash(), $data);

This does:

$this->classarray = array_map(array($this, 'dash'), $data);

Read about the different forms a callback may take here.


Hello You can use Like this one

    // Static outside of class contextarray_map( array( 'ClassName', 'methodName' ), $array );// Static inside class contextarray_map( array( __CLASS__, 'methodName' ), $array );// Non-static outside of object contextarray_map( array( $object, 'methodName' ), $array );// Non-static inside of object contextarray_map( array( $this, 'methodName' ), $array );


array_map($this->dash(), $data) calls $this->dash() with 0 arguments and uses the return value as the callback function to apply to each member of the array. You want array_map(array($this,'dash'), $data) instead.