php map 空,PHP-array_map在类中不起作用

我正在尝试创建一个处理数组的类,但是似乎无法让array_map()在其中工作。

//Create the test array

$array = array(1,2,3,4,5,6,7,8,9,10);

//create the test class

class test {

//variable to save array inside class

public $classarray;

//function to call array_map function with the given array

public function adding($data) {

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

}

// dash function to add a - to both sides of the number of the input array

public function dash($item) {

$item2 = '-' . $item . '-';

return $item2;

}

}

// dumps start array

var_dump($array);

//adds line

echo '
';

//creates class object

$test = new test();

//classes function adding

$test->adding($array);

// should output the array with values -1-,-2-,-3-,-4-...

var_dump($test->classarray);

这个输出

Warning: array_map() expects parameter 1 to be a valid callback, function '--' not found or invalid function name in D:\xampp\htdocs\trainingdvd\arraytesting.php on line 11 NULL

Warning: array_map() expects parameter 1 to be a valid callback, function '--' not found or invalid function name in D:\xampp\htdocs\trainingdvd\arraytesting.php on line 11 NULL

Warning: array_map() expects parameter 1 to be a valid callback, function '--' not found or invalid function name in D:\xampp\htdocs\trainingdvd\arraytesting.php on line 11 NULL

我在做什么错或该功能在类内部不起作用?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值