Reputation: 367
I have this object array $work_breaks (Var_dump):
array(2) {
[0]=>
object(stdClass)#3717 (7) {
["ID"]=>
string(1) "7"
["location"]=>
string(1) "0"
["service"]=>
string(1) "0"
["worker"]=>
string(1) "3"
["status"]=>
string(4) "open"
["hours"]=>
string(624) "a:7:{s:6:"Sunday";a:3:{s:6:"active";s:2:"no";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}s:6:"Monday";a:3:{s:6:"active";s:2:"no";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}s:7:"Tuesday";a:3:{s:6:"active";s:2:"no";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}s:9:"Wednesday";a:3:{s:6:"active";s:3:"yes";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}s:8:"Thursday";a:3:{s:6:"active";s:2:"no";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}s:6:"Friday";a:3:{s:6:"active";s:2:"no";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}s:8:"Saturday";a:3:{s:6:"active";s:2:"no";s:5:"start";s:5:"00:00";s:3:"end";s:5:"00:30";}}"
["note"]=>
string(0) ""
}
[1]=>
object(stdClass)#3935 (7) {
["ID"]=>
string(1) "8"
["location"]=>
string(1) "0"
["service"]=>
string(1) "0"
["worker"]=>
string(1) "3"
["status"]=>
string(6) "closed"
["hours"]=>
string(37) "a:1:{s:16:"exceptional_days";s:0:"";}"
["note"]=>
string(0) ""
}
}
I'm trying to replace the serialised array in [hours] where [status] = open with a new seralised array $newSchedule by doing:
$work_breaks['hours'] = $newTimes;
but I can't seem to get it to work. How would I do a conditional check if [status] is 'open'?
Upvotes: 1
Views: 9418
Reputation: 54831
As every item of array is stdClass
object you should use ->
instead of square brackets.
foreach ($work_breaks as $item) {
if ($item->status == 'open') {
// do something
$item->hours = 'Your value';
}
}
Upvotes: 3