php - Simple way to get only non-numeric keys from an array -



php - Simple way to get only non-numeric keys from an array -

so have php array so:

array ( [0] => array ( [offset] => 1 [0] => 1 [name] => value:990937970 [1] => value:990937970 ) [1] => array ( [offset] => 2 [0] => 2 [name] => value:482758260 [1] => value:482758260 ) [2] => array ( [offset] => 3 [0] => 3 [name] => value:2045053536 [1] => value:2045053536 ) )

but want alter numeric keys not returned, this:

array ( [0] => array ( [offset] => 1 [name] => value:990937970 ) [1] => array ( [offset] => 2 [name] => value:482758260 ) [2] => array ( [offset] => 3 [name] => value:2045053536 ) )

my question: there simple way (without foreach or while loop) strip out these numeric keys?

i know can foreach check if $key string; however, loops add together code's cyclomatic complexity trying avoid them.

well, if really don't want utilize foreach, can do:

array_walk($data, function (&$v) { $keys = array_filter(array_keys($v), function($k) {return !is_int($k);}); $v = array_intersect_key($v, array_flip($keys)); });

array_walk() still looping foreach would; isn't explicitly shown.

also, mario said, modifying database query much recommended course of study of action this. if must on php side, foreach lot more efficient.

demo

php arrays

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -