【发布时间】:2015-11-12 02:14:00
【问题描述】:
我对 PHP 比较陌生,我不明白为什么我的代码无法将字符串值附加到数组。
从我读过的关于该主题的所有内容中,这段代码:
global $tom_period_parent_title;
$tom_period_parent_title = array();
$tom_period_parent_title[] = 'test';
array_push ($tom_period_parent_title, 'tester');
我应该相信会产生这个结果吗:
tom_period_parent_title
Array
(
[0] => 'test'
[1] => 'tester'
)
但由于某种原因,我不明白,也没有在网上找到任何提及,我得到了这个:
tom_period_parent_title
Array
(
[0] => 0
[1] => 1
)
谁能帮我理解如何进行这项工作?
【问题讨论】:
-
向我们展示您的真实代码。
-
你是怎么得到
0和1的? eval.in/418483 -
我应该指定的,这是一个全局变量。我正在用Debug This读取全局变量,我认为这是值得信赖的。
-
什么是
Debug This?在你的array_push 之后运行print_r($tom_period_parent_title);。 -
我刚刚复制并运行了您的代码,它产生的正是您想要的......在代码末尾添加
print_r( $tom_period_parent_title )以查看......