-1

We saved address as below image in Database :

enter image description here

Here 803110 is zip code of customer, i tried to fetch this zip code and pass it in array as below :

$sqlh="SELECT order_id, address  FROM do_order where order_id='".$order_id."'";
$resulth = $db_handle->runSelectQuery($sqlh);

$address=explode(",",$resulth['address']);
$countadd=count($address);
$pincode=$address[$countadd-1];

$data = 
array (
'OrderNo' => $order_id,
'ZipCode' => $pincode,
);

I got Notice: Undefined index: address & i tried this link before posting question, but that not worked for me....

here is full code in pastebin

1 Answers1

0

You can get the last element of an array using the end() function.

Try this

$address = explode(",",$resulth['address']); 
//or can try explode(",",$resulth[0]['address']) if $resulth is multidimensional array
$pincode = end($address);

Demo

Vidhyut Pandya
  • 1,605
  • 1
  • 14
  • 27