0

Schedule

[
    {"Monday":"11:30"},
    {"Monday":"12:00"},
    {"Monday":"23:00"},
    {"Tuesday":"11:30"},
    {"Tuesday":"12:00"},
    {"Tuesday":"23:00"}
]

Booked Slots

[
    {"Monday":"11:30"},
    {"Tuesday":"23:00"}
]

The third Array should be of (available slots)

[
    {"Monday":"12:00"},
    {"Monday":"23:00"},
    {"Tuesday":"11:30"},
    {"Tuesday":"12:00"}
]

How can I achieve this?

0

1 Answer 1

0

use array_diff

print_r(array_diff(['{"Monday":"11:30"}','{"Monday":"12:00"}','{"Monday":"23:00"}','{"Tuesday":"11:30"}','{"Tuesday":"12:00"}','{"Tuesday":"23:00"}'], ['{"Monday":"11:30"}','{"Tuesday":"23:00"}']));
Sign up to request clarification or add additional context in comments.

9 Comments

The error comes up: array_diff(): Expected parameter 1 to be an array The difference between your array and mine is that mine doesn't have string params they are enclosed in curly braces without quotes around them ... how to get over this problem.
Yes because {} is used to enclose block or function in PHP. How did you build this array ?
array_push($doctor_timings, array($day_id => $time_id)); $doctorTimings = json_encode($doctor_timings); and to view that array I have to json_encode it otherwise it gives me error
Ok, remove json_endcode. And make like this gist.github.com/zeppi/03ac1bcd3fa2fb5c5adaf7d8a9882645
If you do print_r($doctor_timings) yous see array(array('day' => 'hour'), ...) and is Schedule info?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.