Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is some pseudocode, but it is a start:</p> <pre><code>$strings = []; $flattenArray = function($arr, $level) use (&amp;$strings, &amp;$flattenArray) { foreach($arr as $key=&gt;$value){ $s = &amp;$strings[$level]; if(!isset($s)) { $s = array(); } $s[] = $key; if(is_array($value)) { $flattenArray($value, $level); } else { $s[] = $value; } $level ++; } }; $flattenArray($myArray, 0); foreach($strings as &amp;$arr) { $arr = implode("||", $arr); } </code></pre> <p>Small demo with <a href="http://chat.stackoverflow.com/transcript/message/6987965#6987965">your array</a>: <a href="http://codepad.viper-7.com/CR2SPY" rel="nofollow">http://codepad.viper-7.com/CR2SPY</a> &lt;-- It does not work fully, but it is a start</p> <hr> <h2>Update:</h2> <p>Here is a demo that I <em>think</em> works the way you want: <a href="http://codepad.viper-7.com/shN4pH" rel="nofollow">http://codepad.viper-7.com/shN4pH</a></p> <p>Code: </p> <pre><code>$strings = []; $flattenArray = function($arr, $level, $k = null) use (&amp;$strings, &amp;$flattenArray) { foreach($arr as $key=&gt;$value){ if($k === null) { $s = &amp;$strings[$key]; } else { $s = &amp;$strings[$k]; } if(!isset($s)) { $s = array(); } $str = &amp;$s[$level]; if(!isset($str)) { $str = array(); if($k !== null) { $str[] = $k; } } $str[] = $key; if(is_array($value)) { $flattenArray($value, $level, ($k === null) ? $key : $k); } else { $str[] = is_null($value) ? "null" : $value; } $level ++; } }; $flattenArray($myArray, 0); $all = []; foreach($strings as $k =&gt; $arr){ $new = array(); foreach($arr as $ky =&gt; $ar) { $all[] = implode("||", $ar); } } print_r($all); </code></pre>
 

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