PHP数组输出变量与数组中显示的不同

时间:2015-05-15 14:44:53

标签: php arrays variables

打印时的以下数组显示$ career [2]的值是2010 - 。

然而,无论我尝试什么,这个if方程都不会触发。这些数组变量能以某种方式变化吗?

echo $career[2];

    if($career[2] == "2010-"){
        $career = $career[1];
    } 

阵列$ career的print_r揭示了这个......

 Array ( 
[0] => BIS career 
[1] => CEO of the corp 
[2] => 2010- 
[3] => Leader of R&D 
[4] => 2005-10 
);

VAR DUMP

    array(11) { 
[0]=> string(316) "BIS career " 
[1]=> string(194) " CEO of the corp " 
[2]=> string(163) " 2010- " 
[3]=> string(160) " Leader of R&D " 
[4]=> string(165) " 2005-10 " }

1 个答案:

答案 0 :(得分:1)

你也可以这样做:

echo "...".$career[2]."...";

它将反映空间

尝试:

preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u','',$str);

参考:Trim unicode whitespace in PHP 5.2