dongwen7730 2015-09-27 09:11
浏览 40
已采纳

当extract()用于具有默认键值(0,1,2,...)的数组时会发生什么

I haven't given this much thought before but recently tried an sample code to c what happens when using extract() on an array with default key values, how is it supposed to work there.

    $testArray = array("apple", "ant", "book", "bag");
    extract($testArray);

    print_r($testArray);

    echo "${1}";

where will be the values apple, ant, book, and bag stored after extract() is applied.

This is a simple question but somebody please help me solve it.

  • 写回答

2条回答 默认 最新

  • duanleiming2014 2015-09-27 09:42
    关注

    As it is in your code it would not create any variables because there are not defined keys so the keys are 0, 1, 2... therefore, invalid variable names that will prevent them from being extracted.

    if you use EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID to prefix your keys with something to make them valid variable names then you could see them in

    echo $whateveryourprefixis0; 
    echo $whateveryourprefixis1; 
    echo $whateveryourprefixis2; 
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000