Another PHP technique request

I have two arrays that have identical keys. Is there a ‘nice’ php
construct to sort the first array so that its key order is the same
as the key order of the second?

I can obviously do it with a loop of the second array, rebuilding the
first. I thought it should be do-able with uksort(), but even with a
create_function() I can’t get the master array into the call-back
function. The manual doesn’t say anything about scope and
create_function().

David


David Ledger - Freelance Unix Sysadmin in the UK.
HP-UX specialist of hpUG technical user group (www.hpug.org.uk)
email@hidden
www.ivdcs.co.uk


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

array_multisort() is precisely for this purpose. Have a look at the
manual for the syntax. Note that it will re-sort the second array
(because it’s passed by reference) to be the same as the first one,
while it’s sorting the first array to be like the second. Sort of a
push-me-pull-you.

Walter

On Apr 18, 2011, at 2:33 PM, David Ledger wrote:

I have two arrays that have identical keys. Is there a ‘nice’ php
construct to sort the first array so that its key order is the same
as the key order of the second?

I can obviously do it with a loop of the second array, rebuilding
the first. I thought it should be do-able with uksort(), but even
with a create_function() I can’t get the master array into the call-
back function. The manual doesn’t say anything about scope and
create_function().

David


David Ledger - Freelance Unix Sysadmin in the UK.
HP-UX specialist of hpUG technical user group (www.hpug.org.uk)
email@hidden
www.ivdcs.co.uk


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options