PHP:将字符串值附加到数组

时间:2015-08-18 23:43:46

标签: php arrays append

我对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
)

有人可以帮我理解如何使这项工作吗?

1 个答案:

答案 0 :(得分:0)

感谢chris85向我展示如何使用我的代码实际工作的printr()。问题是我一直在使用的调试器,调试这个用于Wordpress,结果是错误地报告了我的全局数组变量内容。我在其支持页面上报告了该问题。我希望我不会因为这种误解而得到太多的负面代表。谢谢大家。