简体   繁体   English

循环获取PHP脚本中的LDAP条目

[英]Loop to get LDAP entries in PHP script

Getting LDAP data through PHP by using ldap_connect function I want to list all the objectclass items available. 通过使用ldap_connect函数通过PHP获取LDAP数据,我想列出所有可用的objectclass项目。

I got the variable $entries from here so I can print a single entry of my LDAP server when executing the following line: 我从这里获得了变量$ entries,因此执行以下行时可以打印LDAP服务器的单个条目:

var_dump($entries[0]["objectclass"][0]);

For entries with multiple values I am able to do it one by one, I mean: 对于具有多个值的条目,我可以一个接一个地执行,我的意思是:

var_dump($entries[0]["objectclass"][0]);
var_dump($entries[0]["objectclass"][1]);
var_dump($entries[0]["objectclass"][2]);

But I can't get it inside of a for loop like this and I don't understand why: 但是我无法在这样的for循环中获取它,而且我也不明白为什么:

for ($i = 0; $i < 4; $i++){
    echo $i;
    var_dump($entries[0]["objectclass"][$i]);
}

Actually, my purpose is to do it without knowing the maximum number of objectclass I have, so I want to do it within a while loop looking for the objectclass values until I find the NULL value, something like: 实际上,我的目的是在不知道我拥有的最大对象类数量的情况下执行此操作,因此我想在while循环中执行操作以查找对象类值,直到找到NULL值为止,例如:

$i=0;
while (var_dump($entries[0]["objectclass"][$i]) != NULL){
    var_dump($entries[0]["objectclass"][$i]);
    $i++;
}

You should be able to use the count item to iterate the values: 您应该能够使用count项目来迭代值:

for ($i = 0; $i < $entries[0]['objectclass']['count']; $i++) {
    echo $i;
    var_dump($entries[0]["objectclass"][$i]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM