我有很多问题,但我从来没有得到一个好消息。
我有一些函数的响应很好,但问题是正在打印x2我的查询。
我尽量减少我的脚本以快速获得帮助。
是关于array_merge的。
所以第一个
- 验证功能
function Verify($params) {
$query = mysql_query("SELECT SOMETHING");
if ($query->num_rows > 0) {
$row = $query->fetch_assoc();
// Here will pass 2 array on each function to proceed
$data = self::CacheData($row['gid'], $params['sid']);
$data['data'] = self::Host($row['gid'], $params['sid']);
return $tmpdata;
}
return false;
}
- 创建ChacheData和Host函数
static function CacheData($gid, $sid){
$cachedata = array();
$querycache = mysql_query("SELECT WHAT I NEED");
if ($querycache->num_rows == 1) {
$rowcache = $querycache->fetch_assoc();
// Send to Files the array and check if is true
if (self::Files(array('gid' => $gid, 'sid' => $sid, 'expirecache' => 0)) == true) {
return array('gid' => $gid, 'size' => 0, 'enabled' => $rowcache['enabled'], 'exists' => false);
}
}
}
function Host($gid, $sid) {
$query = mysq_query("SELECT WHAT I NEED");
if ($query->num_rows == 0) {
return false;
}
$rowgame = $query->fetch_assoc();
// Send to Files the array and to see if is / false
if (self::Files(array('gid' => $gid, 'sid' => $sid)) == false) {
return false;
}
}
好的,这是我有的问题
当Files接收到2数组时,它正常工作,但我希望所有数组都由其他函数发送到array_merge all。
所以最后一个函数的问题是这样的
function Files(array $params) {
$default = array('skipcache' => false, 'expirecache' => 86400, 'os' => null);
$params = array_merge($default, $params);
//return $params;
print_r($params);
}
现在输出将类似
array(5) {
["skipcache"]=>
bool(false)
["expirecache"]=>
string(1) "0"
["os"]=>
NULL
["gid"]=>
string(1) "1"
["sid"]=>
string(1) "1"
}
array(5) {
["skipcache"]=>
bool(false)
["expirecache"]=>
int(86400)
["os"]=>
NULL
["gid"]=>
string(1) "2"
["sid"]=>
string(1) "1"
}
基于这个输出,我在数据库上添加,但问题是在数据库上增加2,我需要1个数组,而不是2。
所以我看到了array_merge移除duplicates,但在这里我看到了所有它都是一样的,但没有移除,因为$params接收了2个数组!
你能给我一些解决方案吗?但不能给我!
非常感谢!
问候,
您可以尝试:
$uniqueArr = array_merge(array_flip(array_flip($mergedArray)));
或
$uniqueArr = array_keys(array_flip($mergedArray));
或者如果您想使用array_unique方法:
$uniqueArr = array_unique(array_merge($array1,$array2), SORT_REGULAR);
从此链接http://php.net/manual/en/function.array-unique.php这比array_ unique方法快得多。您可以arrayflip,以便将关键帧作为值获取,反之亦然。