Jump to content

exploding array


Boxerman
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hey guys,

 

I've trying to explode and array but having no luck:

 

The array is grabbed via:

$result = $adldap->group()->all($includeDescription = false, $search = "*", $sorted = false);

and the output looks a little like:

array(1500) {
  [0]=>
  string(16) "Exchange Servers"
  [1]=>
  string(36) "Exchange Organization Administrators"
  [2]=>
  string(33) "Exchange Recipient Administrators"
  [3]=>
  string(33) "Exchange View-Only Administrators"
  [4]=>
  string(37) "Exchange Public Folder Administrators"
  [5]=>
  string(21) "ExchangeLegacyInterop"
  [6]=>

The command i have so far is:

foreach ($result as $group) {
    $items = explode('[', $group);
    foreach($items as $element) {
        list($key, $value) = explode('"', $element);
        if ($key==']') {
            echo "$value</a>";
        }
    }
}

I honestly don't know what to use for the explode as i wanted to try starting with ) and ending with " but i can't get my head around the idea..

 

Any help would be high fived. 

 

Thanks!

Link to comment
Share on other sites

There isn't a [ in any of the array values, so that isn't going to work.  The only common thing between all the array items is the word Exchange.  Not much else you could consistently explode by in that array.  The [ and ] symbols are the array keys, not the array items.

Link to comment
Share on other sites

  • Solution

The output you see is what you get by passing $result to var_dump(), this will print the structure of the array and show the data types of the values stored in the array.

 

You do not need to use explode to get the value from the array. You loop over the values in the the array using foreach and echo the value of the current item

$result = $adldap->group()->all($includeDescription = false, $search = "*", $sorted = false); // this returns an array of results

var_dump($result); // this will print the structure of the array

// this loops over the items in the array and prints each value
foreach ($result as $value)
{
    echo $value . '<br />';
}

Explode is used for splitting a string into an array.

Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.