Jump to content

exploding array


Boxerman

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
https://forums.phpfreaks.com/topic/296355-exploding-array/
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
https://forums.phpfreaks.com/topic/296355-exploding-array/#findComment-1512053
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/296355-exploding-array/#findComment-1512061
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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