1

Got an array here:

Array
(
    [0] => Securitygroep
    [1] => Hoofdgroep
    [2] => Belangrijke Groep
    [3] => Testgroep2
    [4] => Beheergroep
    [5] => Mailgroep
    [6] => Domeingebruikers
    [7] => Gebruikers
)

How can I get all the values from the array in this function?

$check = $adldap->group()->info("//value from array");

Or do I have to execute this function in a sort of looping method?

Like this:

$check = $adldap->group()->info("Securitygroep");
$check = $adldap->group()->info("Hoofdgroep");
$check = $adldap->group()->info("Belangrijke Groep");

etc etc...

2
  • 1
    Do you have to send those values in a comma separated list? Commented Apr 30, 2014 at 7:03
  • No, it takes only one value a time. So I need a loop or something with foreach. Commented Apr 30, 2014 at 7:24

4 Answers 4

2

Well, it depends on what the info() method is doing. While you do not provide us such information, we are not able to give you the most accurate answer.

For example, if info method accepts array:

public function info(array $infos) {
    foreach ($infos as $info) {
        // do smth with each element
    }
}

you can pass the array straight to the function:

$check = $adldap->group()->info($array);

if the method accepts only one element, then you need to loop through the array and pass to the method:

foreach ($array as $value) {
    $check = $adldap->group()->info($value);
}

If the method accepts a lot of values at once, i.e. comma separated, you can implode the array

 $check = $adldap->group()->info(implode(',' ,$array));
Sign up to request clarification or add additional context in comments.

2 Comments

foreach works and it only accepts one element, but it's looping the same value every time and that's "Testgroep2". How do I get all the different values to loop in the function?
Never mind, got it working now! I missed placed a {. Now it works perfectly. Thanks, you saved my day.
1
$check = $adldap->group()->info(implode(",",$yourArray));

This will send all the array values to your function in a comma separated string, if that is what you needed.

Otherwise if that method takes only 1 value then you could loop through your array

foreach($myArray as $value)
{
    $check = $adldap->group()->info($value);
}

2 Comments

Yes, my function apparently takes only 1 value a time. So your foreach function works, but it's only looping 1 value from the array and that's "Testgroep2". Why is this happening?
That's not possible provided the array structure is exactly like you mentioned and if the names match too
0

Can the info method be rewritten to accept array as the parameter? Then simply pass it

$check = $adldap->group()->info($myArray);

Comments

0

you can use index

$check = $adldap->group()->info($arr[0]);

$check = $adldap->group()->info($arr[1]); 

and so on..

or you can use foreach

foreach($myArray as $value)
{
    $check = $adldap->group()->info($value);
}

you want to pass all array in a string use implode()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.