开发者

I cannot figure how to to dynamically add values to an array

How can I rewrite this please as I tried a few things and I just dont know the correct way to do it. Instead of:

$files_to_zip = array(
    1,
    4,
    8
);

How can that be rewritten so that:

$explode_mods  = "1,4,8";
$mod_nums = explode(",", $explode_mods);

$files_to_zip = $mod_nums;

Basically $files_to_zip still needs to be in array format but I don't know how to only display each value into an array for the $files_to_zip variable. This is part of a larger script and I am almost done so please do not show me a totally different code I just need $file开发者_JAVA技巧s_to_zip to be read as an array still. The $explode_mods will actually be a $_POST value in the real script where I enter numbers separated by commas and they will be inserted into the $files_to_zip array. Thank you.


I think I read your question correctly: you already have other entries in $files_to_zip which you want to merge with $explode_mods?

Try this:

$files_to_zip = array('some', 'entries', 'here', 'already');
$explode_mods = "1,4,8";
$files_to_zip = array_merge($files_to_zip, explode(',', $explode_mods));
var_dump($files_to_zip);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜