Notice: Undefined offset: 1, but there is such offset

346 Views Asked by At

i have class of paypal pdt, that explode the result with \n, not the array that return from the explode is (i print_r the array that cause the error):

Array ( [0] => SUCCESS [1] => mc_gross=1.00 [2] => protection_eligibility=Eligible [3] => address_status=unconfirmed [4] => payer_id=E8NUM3W3UU2BJ [5] => tax=0.00 [6] => address_street=%E4%E7%F8%E5%E1+11 [7] => payment_date=09%3A02%3A53+Jun+08%2C+2015+PDT [8] => payment_status=Completed [9] => charset=windows-1255 [10] => address_zip= [11] => first_name=%F2%EE%E9%E7%E9 [12] => mc_fee=0.33 [13] => address_country_code=IL [14] => address_name=%F2%EE%E9%F7%E5+%F2%E9%F6%E5%E1%E9%ED [15] => custom=12 [16] => payer_status=unverified [17] => business=Nati323%40gmail.com [18] => address_country=Israel [19] => address_city=%E7%F6%E5%F8+%E4%E2%EC%E9%EC%E9%FA [20] => quantity=1 [21] => payer_email=amiko565%40gmail.com [22] => txn_id=2P772327GW176762T [23] => payment_type=instant [24] => payer_business_name=%F2%EE%E9%F7%E5+%F2%E9%F6%E5%E1%E9%ED [25] => last_name=%E5%F7%F0%E9%EF [26] => address_state= [27] => receiver_email=Nati323%40gmail.com [28] => payment_fee=0.33 [29] => receiver_id=SN8LU9GA56NPJ [30] => txn_type=web_accept [31] => item_name=First+Package [32] => mc_currency=USD [33] => item_number=1 [34] => residence_country=IL [35] => handling_amount=0.00 [36] => transaction_subject=12 [37] => payment_gross=1.00 [38] => shipping=0.00 [39] => ) 

but i get this error:

Notice: Undefined offset: 1 in /home/star1231/public_html/pdt.php on line 37

as you can see there is a key with value '1' in the array, line: 37

list($key,$val) = explode("=", $lines[$i]);

the complete code:

$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
    for ($i=1; $i<count($lines);$i++){
    list($key,$val) = explode("=", $lines[$i]);
    $keyarray[urldecode($key)] = urldecode($val);
}

var_dump of $lines:

array(40) { [0]=> string(7) "SUCCESS" [1]=> string(13) "mc_gross=1.00" [2]=> string(31) "protection_eligibility=Eligible" [3]=> string(26) "address_status=unconfirmed" [4]=> string(22) "payer_id=E8NUM3W3UU2BJ" [5]=> string(8) "tax=0.00" [6]=> string(33) "address_street=%E4%E7%F8%E5%E1+11" [7]=> string(44) "payment_date=09%3A02%3A53+Jun+08%2C+2015+PDT" [8]=> string(24) "payment_status=Completed" [9]=> string(20) "charset=windows-1255" [10]=> string(12) "address_zip=" [11]=> string(26) "first_name=%F2%EE%E9%E7%E9" [12]=> string(11) "mc_fee=0.33" [13]=> string(23) "address_country_code=IL" [14]=> string(50) "address_name=%F2%EE%E9%F7%E5+%F2%E9%F6%E5%E1%E9%ED" [15]=> string(9) "custom=12" [16]=> string(23) "payer_status=unverified" [17]=> string(28) "business=Nati323%40gmail.com" [18]=> string(22) "address_country=Israel" [19]=> string(47) "address_city=%E7%F6%E5%F8+%E4%E2%EC%E9%EC%E9%FA" [20]=> string(10) "quantity=1" [21]=> string(32) "payer_email=amiko565%40gmail.com" [22]=> string(24) "txn_id=2P772327GW176762T" [23]=> string(20) "payment_type=instant" [24]=> string(57) "payer_business_name=%F2%EE%E9%F7%E5+%F2%E9%F6%E5%E1%E9%ED" [25]=> string(25) "last_name=%E5%F7%F0%E9%EF" [26]=> string(14) "address_state=" [27]=> string(34) "receiver_email=Nati323%40gmail.com" [28]=> string(16) "payment_fee=0.33" [29]=> string(25) "receiver_id=SN8LU9GA56NPJ" [30]=> string(19) "txn_type=web_accept" [31]=> string(23) "item_name=First+Package" [32]=> string(15) "mc_currency=USD" [33]=> string(13) "item_number=1" [34]=> string(20) "residence_country=IL" [35]=> string(20) "handling_amount=0.00" [36]=> string(22) "transaction_subject=12" [37]=> string(18) "payment_gross=1.00" [38]=> string(13) "shipping=0.00" [39]=> string(0) "" } 
0

There are 0 best solutions below