Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate new multidimensional array from flat array - directory paths - PHP
    primarykey
    data
    text
    <p>Hope someone can point me in the right direction here...</p> <p>I've got directory paths and partial file outputs form a unix grep. I have a flat array from these outputs. Now I'd like to do a bit of PHP magic to turn this flat array into a more hierarchical multidimensional array for more refined user output</p> <p>Current array;</p> <pre><code>array(7) { [0]=&gt; string(160) "/home/user/data/section1/dir1/20120107/filename.txt:random text after the colon" [1]=&gt; string(160) "/home/user/data/section1/dir1/20120108/filename.txt: More random text after the colon" [2]=&gt; string(160) "/home/user/data/section1/dir2/20120107/filename.txt: More random text after the colon" [3]=&gt; string(160) "/home/user/data/section1/dir2/20120108/filename.txt: More random text after the colon" [4]=&gt; string(160) "/home/user/data/section1/dir3/20120107/filename.txt: More random text after the colon" [5]=&gt; string(160) "/home/user/data/section1/dir3/20120106/filename.txt: More random text after the colon" [6]=&gt; string(160) "/home/user/data/section1/dir3/20120108/filename.txt: More random text after the colon" } </code></pre> <p>What i would really like</p> <pre><code>array(1) { array(3) { ["dir"]=&gt; string(4) "dir1" ["date"]=&gt; string(8) "20120107" ["text"]=&gt; array (2) { [0]=&gt; string(160) "random text after the colon" [1]=&gt; string(160) "More random text after the colon" } } array(3) { ["dir"]=&gt; string(4) "dir1" ["date"]=&gt; string(8) "20120108" ["text"]=&gt; array (2) { [0]=&gt; string(160) "More random text after the colon" [1]=&gt; string(160) "More random text after the colon" } } array(3) { ["dir"]=&gt; string(4) "dir2" ["date"]=&gt; string(8) "20120107" ["text"]=&gt; array (2) { [0]=&gt; string(160) "More random text after the colon" [1]=&gt; string(160) "More random text after the colon" } } } </code></pre> <p>I have tried a lot of foreach's, SPL iterator methods, but i'm just not coming out trumps. Looking for any guidance.</p> <p>Thanks all</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload