doulang6013 2013-01-22 16:26
浏览 78
已采纳

glob()php函数数组格式

Maybe I missed something, but really, I can't find a solution for this.

I want to change the format of the array I get from a glob function.

This is how my code looks now.

$my_files = glob('*.php');

and the result is an array:

array(
    '0' => 'about.php',
    '1' => 'admin-ajax.php',
    '2' => 'admin-footer.php',
    '3' => 'admin-functions.php',
    '4' => 'admin-header.php',
    '5' => 'admin-post.php',
    '6' => 'admin.php',
)

Now this is what exactly I want to have(to change the numbers with the text for each array, respectively):

array(
    'about.php'         => 'about.php',
    'admin-ajax.php'    => 'admin-ajax.php',
    'admin-footer.php'  => 'admin-footer.php',
    'admin-functions.php' => 'admin-functions.php',
    'admin-header.php'  => 'admin-header.php',
    'admin-post.php'    => 'admin-post.php',
    'admin.php'         => 'admin.php',
)

I need this as an array to include it using a variable in this way:

array(
    'name'      => 'Intern download file name',
    'id'        => $prefix .'blog_post_intern_url',
    'type'      => 'select',
    'options'   => $my_files,
),
  • 写回答

2条回答 默认 最新

  • dongxi1879 2013-01-22 16:27
    关注
    $arrayWithKeysEqualValues = array_combine($my_files, $my_files);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳