Ejemplo n.º 1
0
/**
 * 按照value删除数组对应的项
 *
 * @param array $haystack 需要操作的array
 * @param mixed $needles 需要删除的value,可以是value的数组或一个value的字符串
 * @param boolean $strict 是否强制对比类型
 * @return array 返回操作结果
 */
function array_delete(array &$haystack, $needles, $strict = FALSE)
{
    $needles = toarray($needles);
    $_haystack = $haystack;
    foreach ($needles as $needle) {
        $indexes = array_keys($_haystack, $needle, $strict);
        foreach ($indexes as $index) {
            unset($_haystack[$index]);
        }
    }
    return $_haystack;
}
Ejemplo n.º 2
0
function toarray($data, $id)
{
    $bookmarks = array();
    foreach ($data as $entry) {
        $id++;
        $bookmarks['_' . $id] = array('id' => $id, 'type' => $entry['type'], 'name' => $entry['name'], 'date_added' => round($entry['date_added'] / 10000000));
        if ($entry['type'] == 'url') {
            $bookmarks['_' . $id]['url'] = isset($entry['url']) ? $entry['url'] : '';
        } elseif ($entry['type'] == 'folder' && isset($entry['children']) && !empty($entry['children'])) {
            $result = toarray($entry['children'], $id);
            $bookmarks['_' . $id]['entries'] = $result[0];
            $id = $result[1];
        }
    }
    return array($bookmarks, $id);
}