dpevsxjn809817 2014-09-18 09:08
浏览 44
已采纳

从具有未知长度和值名称的关联数组中提取每个值

I have an array like:

Array
(
    [item1] => value1
    [item2] => value
    [item3] => value3
)

And I want to extract all the names and values to variables. But say, I don't know the names of items that the array contains. I wanna generate variables for each array item with the name of this item name in array to make possible of using this variables later. The result should look like this:

item_name1 = item_value1
item_name2 = item_value2
item_name3 = item_value3

Seems the foreach loop should be usefull here.

  • 写回答

2条回答 默认 最新

  • doulvli9462 2014-09-18 09:15
    关注

    I'm not sure if I understood this.

    If you want the key from the array to become a variable with the same name you can use the extract function: http://php.net/manual/en/function.extract.php

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分