8
votes
3answers
6k views

PHP Create a Multidimensional Array from an array with relational data [duplicate]

Possible Duplicate: Converting an array from one to multi-dimensional based on parent ID values I am working in PHP. I have the following array that has relational data (parent child ...
1
vote
2answers
3k views

Multidimensional array iteration

Say you have the following array: $nodes = array( "parent node", "parent node", array( "child node", "child node", array( "grand child node", ...
14
votes
9answers
6k views

PHP 2D Array output all combinations

I've had this problem bending my mind for a while now (head cold doesn't help either!), basically I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1] = 'pears'; ...
1
vote
2answers
919 views

Converting an array from one to multi-dimensional based on parent ID values

I've got a one-dimensional array of objects that represent multi-dimensional data: array( array( "id" => 45, "parent_id" => null ), array( "id" => 200, ...
21
votes
5answers
27k views

PHP tree structure for categories and sub categories without looping a query

I'm trying to create a list of categories with any number of sub categories, where sub categories can also has their own sub categories. I have selected all categories from the Mysql db, the cats are ...
2
votes
5answers
2k views

Walk array recursively and print the path of the walk

Can someone help me with some code or instructions on how to walk recursively an array and when reaching the last element print the full path to it? A simple echo will work because I will adapt the ...
1
vote
5answers
2k views

How to recursively create a multidimensional array?

I am trying to create a multi-dimensional array whose parts are determined by a string. I'm using . as the delimiter, and each part (except for the last) should be an array ex: ...
3
votes
3answers
2k views

Order multidimensional array recursively at each level in PHP

I have an array of this form: Array ( [first_level] => Array ( [dir_3] => Array ( [subdir_1] => Array ( ...
4
votes
2answers
3k views

PHP convert nested array to single array while concatenating keys?

Here is an example array: $foo = array( 'employer' => array( 'name' => 'Foobar Inc', 'phone' => '555-555-5555' ), ...
0
votes
1answer
74 views

Multidimensional Directory List with Recursive iterator

I am trying to get multi-dimensional array for directories formatted as below : [ { "text": "another_folder", "href": "gui\/default\/uploads\/another_folder", "depth": ...
10
votes
6answers
642 views

PHP Array: join each sub-array together (Probability)

I want simply to find-out better way to do this: $array = array( array('a', 'b', 'c'), array('e', 'f', 'g'), array('h', 'i', 'j', 'k', 'l') ); The goals is to print something like this: ...
1
vote
3answers
6k views

PHP recursive array searching

I am using the following function to search through an array recursively: function search2($array, $key){ if( array_key_exists($key, $array) ){ print("<br> ----------------- FOUND ...
0
votes
3answers
909 views

Permutation of multidimension (jagged) array

I'm trying to create a permutation of a multidimensional array in classic asp (vbscript) and I'm seriously stuck. I've tried several functions of my own and also tried copying several php versions ...
4
votes
3answers
976 views

Transform flat array into a hierarchical, multi-dimensional array

I have a standard array with key-value pairs - and I want to use the keys to transform it into a multi-dimensional array. The difficulty seems to be that I need to loop recursively the unknown number ...
3
votes
3answers
268 views

Searching for a key in a multidimensional array then changing a value with PHP

I have a multidimensional array that looks like this [0] => Array ( [recordId] => 5 [leaf] => 1 [children] => Array ( [0] => ...
6
votes
1answer
5k views

How do I use a recursive array iterator to process a multidimensional array?

I'm trying to get something like this working: function posts_formatter (&$posts){ foreach ($posts as $k => $v){ if (is_array($v)){ posts_formatter($v); ...
4
votes
6answers
3k views

Recursive php function that turns nested array into nested html blocks

I'm looking to write a recursive php function that would call a function to generate nested HTML blocks ( not necessarily only DIVs ). So for example, for the following array: $a = array( 'b' ...
1
vote
2answers
3k views

Recursive loop for multidimenional arrays?

I basically want to use str_replace all values of a multidimenional array. I cant seem to work out how I would do this for multidimenional arrays. I get a little stuck when the value is an array its ...
1
vote
3answers
3k views

Array permutations in multidimensional array keeping the keys PHP

For two days I've been running crazy trying to accomplish this, maybe you can enlighten me. This is for a horse betting permutation. Every time a user plays, I get a multidimensional array (2 levels). ...
3
votes
1answer
809 views

Flatten multidimensional associative array to one one-dimensional array of references in PHP

Given I have an array: $array = array( 'a' => array( 'b' => array( 'c' => 'hello', ), ), 'd' => array( 'e' => array( 'f' ...
0
votes
1answer
1k views

Recursive function for building array from tree

I have an array that looks like this: Array ( [0] => Array ( [term_id] => 23 [name] => testasdf [depth] => 1 ) [1] => Array ( ...
2
votes
2answers
841 views

PHP check if some keys or values are in a multidimensional array

I have an array structure where I want to check if a key/value is present somewhere in the array. But I want to make the test in such a way that I make a an almost mirrored validation array. Lets say ...
1
vote
4answers
2k views

How to unset elements using array_walk_recursive

I need to unset elements from arrays that are nested into another array, in a way that only the first N elements would be kept (N being predefined). Only elements that have a numerical index should be ...
0
votes
3answers
1k views

PHP Recurse multidimensional array while keeping hold of depth and key

I've got a multidimensional array containing some id's, stored in keys called 'name'. Each entry can have other sub-arrays, containing other id's. The array is dynamic; the depth and entries are ...