php-array functions

Source: Internet
Author: User

Today, when I was writing an interface to synchronize data with a third party, I had a big piece of data, but the third party needed only a few of them, and it started out as much as I thought.

$ret Array (); foreach ($needParamsas$pk) {    if (isset($params[ $PK ]        ) {$ret[$pk$params[$pk];    }}

Due to the need to deal with some special parameters, looking very uncomfortable

Think of the PHP array function is very powerful, and then changed to

$needkey Array (' uid ', ' cuid '); $params Array (' uid ' = = 123, ' cuid ' + 1234567, ' other ' = ' ... '); $ret = Array_intersect_key ($paramsarray_flip($needkey));

Change into

    /** * _packparams * * @desc extract pass parameters from public parameters according to configuration*/    Private function_packparams ($params,$needKey) {        $ret= Array_intersect_key ($params,$needKey); //special handling of individual parameters        if(isset($ret[' UID '])) {            $ret[' cuid '] =$ret[' UID ']; unset($ret[' UID ']); }        if(isset($needKey[' Puid '])) {            $PASSSRV=$this->getinstance (' Util_passport '); $uid=$PASSSRV->getuidfromcookie ($params[' Cookie ']); $ret[' uid '] =NULL===$uid? ‘‘ :$uid; }        return $ret; }

php-array functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.