I want to access single value of array in array for my following code,
now result:
{"result":[{"msgno":" 1","from":[{"personal":"Blind Mailer","mailbox":"mailerblind","host":"gmail.com"}],"subject":"Testing","date":"Mon, 2 Jan 2017 13:16:21 +0530"}]}
required result:
{"result":[{"msgno":" 1","from":"Blind Mailer","subject":"Testing","date":"Mon, 2 Jan 2017 13:16:21 +0530"}]}
php code:
$emails = imap_search($inbox,'SEEN');
$output = '';
$result=array();
foreach($emails as $ove) {
$headerInfo = imap_headerinfo($inbox,$ove);
$emailStructure = imap_fetchstructure($inbox,$ove);
if(!isset($emailStructure->multipart)) {
array_push($result,array("msgno"=>$headerInfo->Msgno ,"from"=>$headerInfo->from,"subject"=>$headerInfo->subject,"date"=>$headerInfo->date));
} else {
array_push($result,array("msgno"=>$ove->msgno,"from"=>$ove->from,"subject"=>$ove->subject,"date"=>$ove->date));
}
}
echo json_encode(array('result'=>$result));
array_push
will append items to the array. Since what you are appending is itself an array you have an array inside an array rather than all values in a single array.
Instead you want to use array_merge
which will take two arrays and join them together to create a single 1-dimensional array. See the PHP manual here: http://php.net/manual/en/function.array-merge.php