我怎样才能从PHP周期发送整个数组? [英] How can I send whole array from php cycle?
问题描述
我有,我有所有注册用户LDAP服务器。有超过3000用户和LDAP有 1000项作为一个搜索结果的限制。我需要所有的用户在一个JSON和管理等数组。
I have a LDAP server where I have all registered users. There is over than 3000 users and LDAP has 1000 entries limit for one search result. I need to have all users in one 'array' for json and administration and so on.
还有就是我的code搜索结果超过1000项:
There is my code for search result over than 1000 entries:
$bind = ldap_bind($ds, $dn, $ldapconfig['password']);
$pageSize = 100;
$cookie = '';
$i = 0;
$attributes = array("email", "verificationHash", "gn", "sn");
do {
ldap_control_paged_result($ds, $pageSize, true, $cookie);
$filter = '(&(objectClass=Client))';
$result = ldap_search($ds, $baseDN, $filter, $attributes);
$entries = ldap_get_entries($ds, $result);
array_shift( $entries );
$usersJSON = json_encode( $entries );
header('Content-Type: application/json');
echo $usersJSON; // return all users from ldap (over 3000)
ldap_control_paged_result_response($ds, $result, $cookie);
} while($cookie !== null && $cookie != '');
// return array for javascript
$output = json_encode(
array(
'status' => true,
'text' => 'Something',
'data' => $entries
)
);
die($output);
在前端,我需要整个数组,但我得到的只是第一个100个条目。我怎么能循环的结果拆分到一个变量数组?
On front-end I need whole array but I get just first 100 entries. How can I split that result of cycles to one variable array?
推荐答案
我看起来你是在用新数据每次迭代覆盖你的 $项目
阵列。所以我会做这样的事情:
to me it looks like you are overwriting your $entries
array on each iteration with the new data. So I'd do something like this:
…
$entries = array();
do {
…
$entries = array_merge(ldap_get_entries($ds, $result), $entries);
…
} while(…)
unset($entries['count']);
…
array_merge 救援;)
这篇关于我怎样才能从PHP周期发送整个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!