我需要优化或自定义函数来更新对象扩展ArrayObject的索引
示例:
<?php
class MyCollection extends ArrayObject
{
// my logic for collection
}
$collection = new MyCollection([
'first',
'second',
'third',
]); // will output [0 => 'first', 1 => 'second', 2 => 'third']
$collection->offsetUnset(1); // will output [0 => 'first', 2 => 'third']
// some reindex function
$collection->updateIndexes(); // will output [0 => 'first', 1 => 'third']
答案 0 :(得分:1)
使用exchangeArray
将内部数组换成已通过array_values
运行的数组。您可以将其合并到自定义import time
timenow = time.strftime("%X")
awake = "06:00:00" # turn on the lights at 6am
sleep = "22:00:00" # turn off the lights at 10pm
while True:
print (timenow) # print the current time
if awake <= timenow:
print ("Lights On")
elif timenow >= sleep:
print ("Lights Off")
My current output is...
21:55:46
Lights On
21:55:46
Lights On
21:55:46
Lights On
类的方法中:
MyCollection