duanpao9781 2013-10-07 05: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 05: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条)
编辑
预览

报告相同问题?