0

我有两个数组:

$delete = array("Delete" => "Delete");

$folders = array("0" => "folder1","1" => "folder2");

$options = array_merge($delete, $folders);

如何将“移动到”添加到 $folders 并让 $options 保留为数组?

在下拉菜单中,这将显示为:

Delete

Move to folder1

Move to folder2
4

3 回答 3

1

如果要将“移动到”字符串添加到 $folder 数组的每个元素,请尝试以下操作:

$folders = array("0" => "folder1","1" => "folder2");
foreach($folders as $key => $value) {
    $folders[$key] = 'Move to '.$value;
}
$options = array_merge($delete, $folders);

或(基于@zamnuts 的建议)

$folders = array("0" => "folder1","1" => "folder2");

function moveto($n) {  
     return 'Move to '.$n; 
}
$folders = array_map("moveto", $folders);
$options = array_merge($delete, $folders);
于 2013-05-14T00:09:34.867 回答
0

这应该做你需要的:

$folders[] = "Move to";

$options = array_merge($delete, $folders);
于 2013-05-13T23:58:43.797 回答
0

不确定是否是真正的问题,但只需在array_merge()通话后添加$folders[] = "Move to". 由于生成了一个新数组,因此对其或之后array_merge()的任何修改都不会影响.$delete$folders$options

于 2013-05-13T23:59:00.640 回答