Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55676 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50494 invoked from network); 1 Oct 2011 17:07:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Oct 2011 17:07:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=flavius.as@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=flavius.as@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: flavius.as@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:36019] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/00-49946-4E8478E4 for ; Sat, 01 Oct 2011 13:07:49 -0400 Received: by bkar4 with SMTP id r4so3129369bka.29 for ; Sat, 01 Oct 2011 10:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=4kuWXDM+UnxWwcXjqV2OBBnqxO91Z8z7jwtBMGntGkk=; b=r24v4YAJgIQfyUUu5B4ESwmuoyD5xDIIv3Ef2LJTR4DZHHJk/HZ2pIYdn8+/MRtMD/ jz2d64YgcoRArO2tqAeq0hieHeMvldZv+7WnWKiYkF5oH3TEGWTR+BBqP2abGUHweshe Yt8jwrm7UkacXlAi3w2qbUL47erHnmNVdnlCw= Received: by 10.223.37.91 with SMTP id w27mr7414983fad.111.1317488465792; Sat, 01 Oct 2011 10:01:05 -0700 (PDT) Received: from [192.168.2.3] (chello080109207086.1.graz.surfer.at. [80.109.207.86]) by mx.google.com with ESMTPS id o22sm12347165fab.11.2011.10.01.10.01.04 (version=SSLv3 cipher=OTHER); Sat, 01 Oct 2011 10:01:05 -0700 (PDT) Message-ID: <4E87474F.5050501@php.net> Date: Sat, 01 Oct 2011 19:01:03 +0200 Reply-To: flavius@php.net User-Agent: I am harmful. Fear me please :-) Mnenhy/0.7.6.666 MIME-Version: 1.0 To: internals@lists.php.net CC: flavius@php.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: ksort an array internally (OR: interate a numerically-indexed array with respect to the indeces) From: flavius.as@gmail.com (Flavius Aspra) Hi How can I ksort() an array? The default implementation does basically this: zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_key_compare, 0 TSRMLS_CC) but php_array_key_compare() is static in ext/standard/array.c [1] Actually I wouldn't need to sort by key at all if add_index_zval() would put the zval at the "right" [2] place from the beginning. Is there any better alternative to add_index_zval() in this regard? Preferably without going through the hassle of making a round-trip via zend_call_function() "directly" to zif_ksort(). What I need is to zend_hash_move_forward() & co but to get the elements in the order indicated by the numeric indeces. Thanks, Flavius [1] http://lxr.php.net/opengrok/xref/PHP_5_3/ext/standard/array.c#250 [2] I know the HT implementation is made to be generalized enough for other use cases, and as such, there is no "right" order. Thus I'm thinking maybe there's some way to add a new numerically-indexed element to the HT and "teach" the HT to do the bookkeeping in respect to the numeric order. Or maybe a better way to iterate such an array. -- What I cannot create, I do not understand. -- Feynman