Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在输入字段中写入SimpleXML数组中的值_Php_Html_Arrays_Simplexml - Fatal编程技术网

Php 如何在输入字段中写入SimpleXML数组中的值

Php 如何在输入字段中写入SimpleXML数组中的值,php,html,arrays,simplexml,Php,Html,Arrays,Simplexml,我有一个名为$tags的simpleXML数组,其中包含一个标签列表,我希望在加载页面时将其用作输入字段的默认值 我的XML(示例): Array ( [0] => SimpleXMLElement Object ( [0] => tag1 ) [1] => SimpleXMLElement Object ( [0] => tag2 ) ) <input type="text" class="form-control optional

我有一个名为
$tags
的simpleXML数组,其中包含一个标签列表,我希望在加载页面时将其用作输入字段的默认值

我的XML(示例):

Array ( [0] => SimpleXMLElement Object ( [0] => tag1 ) 
        [1] => SimpleXMLElement Object ( [0] => tag2 ) 
)
<input type="text" 
    class="form-control optional sel2" id="tags" name="tags" 
    value="<?php echo $tags; ?>" 
/>
我的HTML(用于演示):

Array ( [0] => SimpleXMLElement Object ( [0] => tag1 ) 
        [1] => SimpleXMLElement Object ( [0] => tag2 ) 
)
<input type="text" 
    class="form-control optional sel2" id="tags" name="tags" 
    value="<?php echo $tags; ?>" 
/>

您只需要将SimpleXmlElement数组转换为字符串数组。然后可以在
内爆()中使用它


仔细想想,我怀疑你是否需要绘制阵列图。在
内爆()
中使用
simplexmlement
应该隐式地将它们转换为字符串,这样就足够了

echo implode(',', $tags);

这里演示~

总体思路:循环xml的值并存储在数组中,然后在标记上进行echo
内爆
。我会尽快接受。:)