Bale
Bale

Reputation: 17

Array values in function

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...

Upvotes: 1

Views: 75

Answers (4)

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

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()

Upvotes: 0

Ivan Yonkov
Ivan Yonkov

Reputation: 7034

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));

Upvotes: 2

aland
aland

Reputation: 2004

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

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

Upvotes: 0

Hanky Panky
Hanky Panky

Reputation: 46900

$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);
}

Upvotes: 1

Related Questions