I am getting value from modal which contains array as well like this:
<?php var_dump( $myaccount);?>
Result:
array (size=1) 0 => object(stdClass)[28]
public 'daysselected' => string '["Monday","Tuesday"]'
public 'due' => string '["2017-06-12","2017-06-13"]'
I am trying to access Monday as single and similarly the date. How can i do so?
I am trying this:
if(!empty($myaccount)){
foreach($myaccount as $it){
echo $it->daysselected[0];//i get '[' only
}
}
if(!empty($myaccount)){
foreach($myaccount as $it){
$days = str_replace(['\'', '"', '[', ']'],'', $it->daysselected );
$daysSelected = explode(',', $days);
echo $daysSelected[0];
}
}
try to use this. But error is somewhere in getting of this value.
If your array format like below :
$myaccount = array('daysselected' => '"Monday","Tuesday"',
'due' => '"2017-06-12","2017-06-13"');
foreach ($myaccount as $key => $value)
{
$val = explode(',', $value);
echo $val[0];
}
Please try this may be help you.
//Try this code, it is cleaner and simpler:
if(!empty($myaccount)){
foreach($myaccount as $it){
eval('$ar = '.$it->daysselected.';');
echo $ar[0];
}
}