Home > Back-end >  Underfined key 1 in an array of 2 keys
Underfined key 1 in an array of 2 keys

Time:10-03

I've the following issue. I've an explode() and as return I've 2 keys. But it still give me an exception of can't find array key 1. But when I debug on key 1 it shows me a correct result. How can this be?

[$first, $last] = explode('-', $hours[$key]['time'], 2);
dd(trim($last));
$days[] = [
    'id' => $hours[$key]['id'],
    'day' => $key,
    'begin_time' => trim($first),
    'end_time' => trim($last),
    'free' => false,
];

Array

  "Monday" => array:3 [▶
    "time" => "9:00 - 14:45"
    "id" => "1098"
    "week" => "1"
  ]

Input Value

"9:00 - 14:45"

CodePudding user response:

the value of $hours[$key]['time'] may not contain "-" so its not getting the value for array [$first, $last] if you put dd() statement then its brack your loop so try print() or echo instead of dd() or dd your whole $hours array before explode dd($hours).

  • Related