duanpao9781 2013-10-07 13:36
浏览 57
已采纳

PHP字符串赋值给数组变量[关闭]

I have written some php code, trying what is to assign a string (tag_of_organization) to a variable and then latter to assign it to array newvar. As i am totally new to php and search a lot for it but cannot find anything, so i am asking it here how to do this. here it is

$organ='tag_of_organization';  
$newvar = array(); 
$newvar["tag_of_organization"] =$organ;
  • 写回答

2条回答 默认 最新

  • dongshuo9350 2013-10-07 13:42
    关注

    You are already correct. put print_r to test print your array

    $organ='tag_of_organization';  
    $newvar = array(); 
    $newvar["tag_of_organization"] =$organ;
    print_r($newvar);
    

    Output

    Array ( [tag_of_organization] => tag_of_organization ) 
    

    Update

    you want dynamic result

    $organ='tag_of_organization';  
    $newvar = array(); 
    $newvar[$organ] =$organ;
    print_r($newvar);
    

    Output

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

报告相同问题?

悬赏问题

  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改