मैं सरणी को संभालने के लिए कक्षा बनाने की कोशिश कर रहा हूं लेकिन मुझे इसमें काम करने के लिए array_map()
नहीं मिल रहा है।array_map कक्षाओं में काम नहीं कर रहा है
<?php
//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 '<br />';
//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);
यह आउटपुट
array(10) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) }
Warning: Missing argument 1 for test::dash(), called in D:\xampp\htdocs\trainingdvd\arraytesting.php on line 11 and defined in D:\xampp\htdocs\trainingdvd\arraytesting.php on line 15
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
क्या मैं गलत कर रहा हूँ या इस समारोह बस के अंदर कक्षाएं काम नहीं करता है?
के संभावित डुप्लिकेट की तरह उपयोग कर सकते हैं [पासिंग वस्तु विधि array_map करने के लिए()] (http://stackoverflow.com/questions/4546614/passing-object-method-to- सरणी-मानचित्र) – Gordon