4 ms·
I finally found a use for mixed string/int keys. I have a routine that plucks key/value pairs out of one associative array and builds another, and allows you t
by apinstein 12y ago
I finally found a use for mixed string/int keys.
I have a routine that plucks key/value pairs out of one associative array and builds another, and allows you to rename the resulting key names at the same time. Using mixed keys allows you to be more terse if you don't want to change the name:
$json = $data->valuesForKeyPaths(array(
'foo' => 'path.to.foo',
'bar',
'baz' => 'path.to.baz',
));
- ptx 12y agoGood find. But you could easily do it with lists and tuples in many other languages, for example in Python: json = data.valuesForKeyPaths([('foo', 'path.to.foo'), 'bar', ('baz', 'path.to.baz')])