Using global variables in array_map

时间:2019-03-19 14:39:48

标签: php multidimensional-array array-map

I have an array of 256*256, and the SetRow function changes all values of $arr[$iv] to $x. I have come up with the following:

$arr = array();
$i   = 0;
$j   = 0;
for ($i = 0; $i <= 255; $i++) {
        $arr[$i] = array();

        for ($j = 0; $j <= 255; $j++) {
            $arr[$i][$j] = 0;
        }
    }

function SetRow($iv, $x) {
        global $arr;

        $arr[$iv] = array_map(function($item) {
            global $x;
            $item = $x;

            return $item;
        }, $arr[$iv]);
    }

However, when I do echo $x inside the array_map, it returns nothing(all the values of $arr[$iv] are also empty), and yet I have not understood what is the reason. Thanks a lot for all the replies in advance.

0 个答案:

没有答案