1

Here my code:

 public function getTime(){
       $store = $this->getStoreId();
       $mapping_time = $this->scopeConfig->getValue(self::XPATH_HOURMAX, ScopeInterface::SCOPE_STORE, $store);
       $postTime = unserialize($mapping_time);
       $time_array =array();
       foreach ($postTime as $key => $value) {
       $time_array[trim($value['field1'])] = 
     [
        trim($value['field1']),
        trim($value['field2'])
    ];
     }
       return $time_array;
}

Actual result :

enter image description here

output:

enter image description here

my expection is:

   value                  option
9:30 AM - 2:30 AM : "9:30 AM - 2:30 AM "
6:30 AM - 9:30 AM : "6:30 AM - 9:30 AM "
3:30 AM - 9:30 AM : "3:30 AM - 9:30 AM "

1 Answer 1

2

If I understand the question correctly it sounds like within your foreach $value is an array with two values (keys field1 and field2), and you would like both the value and label of the dropdown options to be a string with both values concatenated by a hyphen.

If this is correct you could do this in a couple of ways. Using simple concatenation:

$valueString = $value['field1'] . ' - ' . $value['field2'];
$time_array[trim($valueString)] = $valueString;

Or you could use php functions array_values and implode:

$valueString = implode(" - ", array_values($value));
$time_array[trim($valueString)] = $valueString;
1
  • thanks above logic help me @rain2o Commented Feb 23, 2019 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.