优化重新索引ArrayObject

时间:2018-09-24 12:28:14

标签: php reindex arrayobject

我需要优化或自定义函数来更新对象扩展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']

1 个答案:

答案 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

请参见https://3v4l.org/S8I7Z