Real Development Encounters problems:
How do I pass each element of an array as an argument to a mutable parameter function?
From MySQL to find multiple data, for an array result set, eg: ['张三','李四', 'foo', 'bar']
;
The type that needs to be written to the result set Redis
SET
;
The Redis PHP Operation class Library provides sAdd()
methods, using the following examples:
Examples of Use:
$redis->sadd (' Key1 ', ' member1 '); /* 1, ' key1 ' = ' {' member1 '} */$redis->sadd (' Key1 ', ' member2 ', ' Member3 '); /* 2, ' key1 ' = ' = ' member1 ', ' member2 ', ' Member3 '}*/$redis->sadd (' Key1 ', ' member2 '); /* 0, ' key1 ' = ' member1 ', ' member2 ', ' Member3 '}*/
Because sAdd()
it is a mutable parameter method, then the problem comes:
How to use the above ['张三','李四', 'foo', 'bar']
$redis->sAdd('key1' , '张三', '李四', 'foo', 'bar');
, instead of using the following loops:
$redis->multi (); foreach ([' Zhang San ', ' John Doe ', ' foo ', ' Bar '] as $value) { $redis->sadd (' Key1 ', $value);} $redis->exec ();
Reply content:
Real development encounters a problem: how do I pass in an array of each element as an argument to a mutable parameter function?
From MySQL to find multiple data, for an array result set, eg: ['张三','李四', 'foo', 'bar']
;
The type that needs to be written to the result set Redis
SET
;
The Redis PHP Operation class Library provides sAdd()
methods, using the following examples:
Examples of Use:
$redis->sadd (' Key1 ', ' member1 '); /* 1, ' key1 ' = ' {' member1 '} */$redis->sadd (' Key1 ', ' member2 ', ' Member3 '); /* 2, ' key1 ' = ' = ' member1 ', ' member2 ', ' Member3 '}*/$redis->sadd (' Key1 ', ' member2 '); /* 0, ' key1 ' = ' member1 ', ' member2 ', ' Member3 '}*/
Because sAdd()
it is a mutable parameter method, then the problem comes:
How to use the above ['张三','李四', 'foo', 'bar']
$redis->sAdd('key1' , '张三', '李四', 'foo', 'bar');
, instead of using the following loops:
$redis->multi (); foreach ([' Zhang San ', ' John Doe ', ' foo ', ' Bar '] as $value) { $redis->sadd (' Key1 ', $value);} $redis->exec ();
Call_user_func_array$redis->multi (); foreach ([' Zhang San ', ' John Doe ', ' foo ', ' Bar '] as $key = = $value) {$redis->sadd (' key ') . $key, $value);} $redis->exec ();
This is how PHP passes each element of an array as an argument to a mutable parameter function. For more information, please pay attention to topic.alibabacloud.com (www.php.cn)!
Related articles:
PHP variable parameters
The difference instance code between JS and PHP passing variable parameters to a function
PHP variable parameter implementation