I’m wanting to do something that I would have thought would be often
required - but I can’t find a function for it.
I have a large associative array $a1 and I want to generate a
sub-array $a3 consisting only of those elements of $a1 whose keys are
included in a list. The list could be keys or values of another
array, $a2.
Like array_replace(), but without the “If the key exists in the
second array, and not the first, it will be created in the first
array.”
Like array_intersect_key(), but with the two arrays being allowed to
be different lengths.
Like array_intersect_assoc(), but with the values not having to be
equal as well as the keys.
Can’t see one in the list in the manual at php.net. Can write my own
easily enough, but I’d rather not if it’s already there, hiding.
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
I’m wanting to do something that I would have thought would be often required - but I can’t find a function for it.
I have a large associative array $a1 and I want to generate a sub-array $a3 consisting only of those elements of $a1 whose keys are included in a list. The list could be keys or values of another array, $a2.
Like array_replace(), but without the “If the key exists in the second array, and not the first, it will be created in the first array.”
Like array_intersect_key(), but with the two arrays being allowed to be different lengths.
Like array_intersect_assoc(), but with the values not having to be equal as well as the keys.
Can’t see one in the list in the manual at php.net. Can write my own easily enough, but I’d rather not if it’s already there, hiding.
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
I’m wanting to do something that I would have thought would be often required - but I can’t find a function for it.
I have a large associative array $a1 and I want to generate a sub-array $a3 consisting only of those elements of $a1 whose keys are included in a list. The list could be keys or values of another array, $a2.
Like array_replace(), but without the “If the key exists in the second array, and not the first, it will be created in the first array.”
Like array_intersect_key(), but with the two arrays being allowed to be different lengths.
Like array_intersect_assoc(), but with the values not having to be equal as well as the keys.
Can’t see one in the list in the manual at php.net. Can write my own easily enough, but I’d rather not if it’s already there, hiding.
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
I’m wanting to do something that I would have thought would be often
required - but I can’t find a function for it.
I have a large associative array $a1 and I want to generate a sub-
array $a3 consisting only of those elements of $a1 whose keys are
included in a list. The list could be keys or values of another
array, $a2.
Like array_replace(), but without the “If the key exists in the
second array, and not the first, it will be created in the first
array.”
Like array_intersect_key(), but with the two arrays being allowed to
be different lengths.
Like array_intersect_assoc(), but with the values not having to be
equal as well as the keys.
Can’t see one in the list in the manual at php.net. Can write my own
easily enough, but I’d rather not if it’s already there, hiding.
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
Seems an obvious function to include. More so than many that are
there. The included functions are a really odd and incomplete bunch.
Are the built-in functions binary, in a pseudo code, or interpreted?
David
At 15:19 -0400 7/4/11, Walter Lee Davis wrote:
I’m surprised there isn’t something native, but this will certainly work:
I’m wanting to do something that I would have thought would be
often required - but I can’t find a function for it.
I have a large associative array $a1 and I want to generate a
sub-array $a3 consisting only of those elements of $a1 whose keys
are included in a list. The list could be keys or values of another
array, $a2.
Like array_replace(), but without the “If the key exists in the
second array, and not the first, it will be created in the first
array.”
Like array_intersect_key(), but with the two arrays being allowed
to be different lengths.
Like array_intersect_assoc(), but with the values not having to be
equal as well as the keys.
Can’t see one in the list in the manual at php.net. Can write my
own easily enough, but I’d rather not if it’s already there, hiding.
–
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
The included functions are compiled C code, so they run pretty fast. But foreach is compiled, and array lookups are very fast, since they run in memory, so my long-hand loop code should be nearly as fast as some hypothetical native function.