note 94403 added to function.array-intersect-key

From: Date: Tue, 03 Nov 2009 01:03:39 +0000
Subject: note 94403 added to function.array-intersect-key
Groups: php.notes 
Request: Send a blank email to php-notes+get-162348@lists.php.net to get a copy of this message
A Q&D way to grab a specific entry from an assoc array returned from a function as a one liner: Normally when a function returns an array, and you only want part of that array, you have to do: <?php $a=func(); $z=$a["desired"]; ... // use $z ?> However, using an immediate array as the second argument to array_intersect_key allows you to skip this explicit assignment step: <?php $z=array_intersect_key(func(),Array("desired"=>"")); ... // use $z ?> This may be appreciated by those who have been spoiled by the ability of e.g. Python to do: <?python z = func()["desired"] ?> ---- Server IP: 64.71.164.2 Probable Submitter: 174.46.204.210 ---- Manual Page -- http://www.php.net/manual/en/function.array-intersect-key.php Edit -- https://master.php.net/note/edit/94403 Del: integrated -- https://master.php.net/note/delete/94403/integrated Del: useless -- https://master.php.net/note/delete/94403/useless Del: bad code -- https://master.php.net/note/delete/94403/bad+code Del: spam -- https://master.php.net/note/delete/94403/spam Del: non-english -- https://master.php.net/note/delete/94403/non-english Del: in docs -- https://master.php.net/note/delete/94403/in+docs Del: other reasons-- https://master.php.net/note/delete/94403 Reject -- https://master.php.net/note/reject/94403 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162348) next »