我下面的數組:檢查數組值與if語句總是返回(輸出)假(否則)
Array
(
[0] => class="amount">€39,00
[2] => class="subscription-details">
[4] => für
[5] => 1
[6] => month
)
我要檢查,如果該值的第六個要素是「月」。
我用這個代碼:
print_r($test[6]); //Output month
if($test[6] == 'month'){
echo 'Alex'; //should output
}else{
echo 'Ecke'; //will output
}
爲什麼這段代碼將輸出「艾克」,而不是「亞歷克斯」?
編輯:
var_dump($test[6])
輸出=串(12)
var_export($test[6])
輸出= '月'
var_export($測試)=
<pre>array (
0 => '<span',
1 => 'class="amount">€39,00</span>',
2 => '<span',
3 => 'class="subscription-details">',
4 => 'für',
5 => '1',
6 => 'month</span>',
)</pre>
之外,你可能在這個字符串中有一些不可打印的字符,用這種方法你可以判斷數組值中是否有任何不可見的字符(如空格) –
我認爲var_export '爲整個陣列可能會更好,因爲這允許複製/粘貼的代碼,並進行一個簡單的測試:) –
是的..我編輯它:p – cgee