解釋這一請:)爲什麼分配順序的這種改變會改變變量的內容?
如果我運行
$custId = getExternalId();
echo $custId . "\n"; // Prints foobar_16262499_1
$serial = '';
$custId = explode('_', $custId);
var_dump($custId);
$custId = $custId[1];
$serial = $custId[2];
die("custId: $custId serial: $serial\n");
我得到
custId: 16262499 serial: 2
這是不正確的。串行應該是1。但是,如果我改變分配的順序,以
$custId = getExternalId();
echo $custId . "\n"; // Prints foobar_16262499_1
$serial = '';
$custId = explode('_', $custId);
var_dump($custId);
$serial = $custId[2]; // Change order here!!!
$custId = $custId[1];
die("custId: $custId serial: $serial\n");
它的工作原理,並給了我
custId: 16262499 serial: 1
爲什麼?
在這兩種情況下,陣列的var_dump產生相同的輸出:
array(3) {
[0]=>
string(4) "foobar"
[1]=>
string(8) "16262499"
[2]=>
string(1) "1"
}
我運行PHP/5.3.3 ZendServer對其進行訪問
嫌HEAD ...我怎麼能錯過顯而易見的:)...