2010-04-23 10 views
3
$arrg = array(); 
if(str_word_count($str) > 1) { 
    $input_arr = explode(' ', $str); 
    die(print_r($input_arr)); 
    $count = count($input_arr); 
    die($count); 

上面是函數的一部分。 當我跑我得到;不返回填充陣列的計數編號

 
Array (
    [0] => luke 
    [1] => snowden 
    [2] => create 
    [3] => develop 
    [4] => web 
    [5] => applications 
    [6] => sites 
    [7] => alse 
    [8] => dab 
    [9] => hand 
    [10] => design 
    [11] => love 
    [12] => helping 
    [13] => business 
    [14] => thrive 
    [15] => latest 
    [16] => industry 
    [17] => developer 
    [18] => act 
    [19] => designs 
    [20] => php 
    [21] => mysql 
    [22] => jquery 
    [23] => ajax 
    [24] => xhtml 
    [25] => css 
    [26] => de 
    [27] => montfont 
    [28] => award 
    [29] => advanced 
    [30] => programming 
    [31] => taught 
    [32] => development 
    [33] => years 
    [34] => experience 
    [35] => topic 
    [36] => fully 
    [37] => qualified 
    [38] => electrician 
    [39] => city 
    [40] => amp 
    [41] => guilds 
    [42] => level) 

哪一個我期待;然而,這並沒有什麼

運行返回:

$arrg = array(); 
if(str_word_count($str) > 1) { 
    $input_arr = explode(' ', $str); 
    //die(print_r($input_arr)); 
    $count = count($input_arr); 
    die($count); 

回答

2

嗯。是否這樣做是因爲$ count是一個整數,我想知道?如果你死(strval($ count)),會發生什麼?

11
die($count); 

殺死與$count(整數)你的腳本作爲exit code

你會想:

die((string) $count); 

5

http://www.php.net/manual/en/function.exit.php(同死())(或類似):

如果狀態是一個字符串,這個功能 在退出之前打印狀態。

如果狀態是一個整數,則該值 也將用作退出狀態。 退出狀態應該在0 到254的範圍內,退出狀態255是由PHP保留的 ,不得使用。 狀態0用於成功終止 程序。

+2

可以說這是錯誤的,不是嗎? 「也會」應該是「會」。 :) – deceze 2010-04-23 08:48:28

+1

你應該把它傳遞給php文檔組,呃? – zaf 2010-04-23 09:06:32

+2

完成。 :) http://bugs.php.net/bug.php?id=51644 – deceze 2010-04-23 09:26:37

2

die()如果是數字,將不會打印參數,而是將其用作退出狀態代碼。

的問題是隻有你的調試技術...:O)

0

整數參數死被用作該過程的退出代碼(模具相當於退出)。只需檢查documentation

1

你試過輸出$ count嗎?此刻你用$ count殺掉你的scrippt作爲errorcode。模擬做

die(print($count)); 

得到你想要的。

+0

這實際上是一個非常整潔的解決方案,因爲'print'返回'1',所以在打印之後,'die( );'仍然得到一個錯誤代碼來處理。當然,這是調試代碼,所以它不如它有用,但總體上這個結構值得記住。 +1 – pinkgothic 2010-04-23 09:00:16