• convert array keys to paths

    From alex@21:1/5 to All on Mon Jun 28 12:57:14 2021
    Look at this array

    array (
    'a' =>
    array (
    'b1' =>
    array (
    'c1' => 1,
    'c2' => 2,
    'c3' => 3,
    ),
    'b2' =>
    array (
    'c' => 4,
    ),
    ),
    )

    You can convert it to

    array (
    'a/b1/c1' => 1,
    'a/b1/c2' => 2,
    'a/b1/c3' => 3,
    'a/b2/c' => 4,
    )

    Possibly without using a complex set of instructions:
    foeach, array_map (), etc.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=c3=b8j?=@21:1/5 to alex on Fri Jul 23 21:14:29 2021
    On 6/28/2021 6:57 AM, alex wrote:
    Look at this array

    array (
      'a' =>
      array (
        'b1' =>
        array (
          'c1' => 1,
          'c2' => 2,
          'c3' => 3,
        ),
        'b2' =>
        array (
          'c' => 4,
        ),
      ),
    )

    You can convert it to

    array (
      'a/b1/c1' => 1,
      'a/b1/c2' => 2,
      'a/b1/c3' => 3,
      'a/b2/c' => 4,
    )

    Possibly without using a complex set of instructions:
    foeach, array_map (), etc.

    A little bit of complexity may be needed.

    :-)

    I came up with:

    function pathjoin_help($o, $elms, &$res) {
    if(is_int($o)) {
    $res[implode('/', $elms)] = $o;
    } else if(is_array($o)) {
    $elms[] = null;
    foreach($o as $pathelm => $value) {
    $elms[count($elms)-1] = $pathelm;
    pathjoin_help($value, $elms, $res);
    }
    } else {
    die("Houston we have a problem");
    }
    }

    function pathjoin($a) {
    $res = array();
    pathjoin_help($a, array(), $res);
    return $res;
    }

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From alex@21:1/5 to All on Sat Jul 24 09:06:47 2021
    Il 24/07/21 03:14, Arne Vajhøj ha scritto:
    On 6/28/2021 6:57 AM, alex wrote:
    Look at this array

    array (
       'a' =>
       array (
         'b1' =>
         array (
           'c1' => 1,
           'c2' => 2,
           'c3' => 3,
         ),
         'b2' =>
         array (
           'c' => 4,
         ),
       ),
    )

    You can convert it to

    array (
       'a/b1/c1' => 1,
       'a/b1/c2' => 2,
       'a/b1/c3' => 3,
       'a/b2/c' => 4,
    )

    Possibly without using a complex set of instructions:
    foeach, array_map (), etc.

    A little bit of complexity may be needed.

    :-)

    I came up with:

    function pathjoin_help($o, $elms, &$res) {
        if(is_int($o)) {
            $res[implode('/', $elms)] = $o;
        } else if(is_array($o)) {
            $elms[] = null;
            foreach($o as $pathelm => $value) {
                $elms[count($elms)-1] = $pathelm;
                pathjoin_help($value, $elms, $res);
            }
        } else {
            die("Houston we have a problem");
        }
    }

    function pathjoin($a) {
        $res = array();
        pathjoin_help($a, array(), $res);
        return $res;
    }

    Arne

    function pathjoin_help($o, $elms, &$res) {
    if(is_int($o)) {
    $res[implode('/', $elms)] = $o;
    } else if(is_array($o)) {
    $elms[] = null;
    foreach($o as $pathelm => $value) {
    $elms[count($elms)-1] = $pathelm;
    pathjoin_help($value, $elms, $res);
    }
    } else {
    die("Houston we have a problem");
    }
    }

    function pathjoin($a) {
    $res = array();
    pathjoin_help($a, array(), $res);
    return $res;
    }

    print_r(
    pathjoin(
    array (
    'a' =>
    array (
    'b1' =>
    array (
    'c1' => '1',
    'c2' => 2,
    'c3' => 3,
    ),
    'b2' =>
    array (
    'c' => 4,
    ),
    ),
    )
    )
    );

    Houston we have a problem

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=c3=b8j?=@21:1/5 to alex on Sat Jul 24 20:36:51 2021
    On 7/24/2021 3:06 AM, alex wrote:
    Il 24/07/21 03:14, Arne Vajhøj ha scritto:
    On 6/28/2021 6:57 AM, alex wrote:
    Look at this array

    array (
       'a' =>
       array (
         'b1' =>
         array (
           'c1' => 1,
           'c2' => 2,
           'c3' => 3,
         ),
         'b2' =>
         array (
           'c' => 4,
         ),
       ),
    )

    You can convert it to

    array (
       'a/b1/c1' => 1,
       'a/b1/c2' => 2,
       'a/b1/c3' => 3,
       'a/b2/c' => 4,
    )

    Possibly without using a complex set of instructions:
    foeach, array_map (), etc.

    A little bit of complexity may be needed.

    :-)

    I came up with:

    function pathjoin_help($o, $elms, &$res) {
         if(is_int($o)) {
             $res[implode('/', $elms)] = $o;
         } else if(is_array($o)) {
             $elms[] = null;
             foreach($o as $pathelm => $value) {
                 $elms[count($elms)-1] = $pathelm;
                 pathjoin_help($value, $elms, $res);
             }
         } else {
             die("Houston we have a problem");
         }
    }

    function pathjoin($a) {
         $res = array();
         pathjoin_help($a, array(), $res);
         return $res;
    }

    Arne

    function pathjoin_help($o, $elms, &$res) {
        if(is_int($o)) {
            $res[implode('/', $elms)] = $o;
        } else if(is_array($o)) {
            $elms[] = null;
            foreach($o as $pathelm => $value) {
                $elms[count($elms)-1] = $pathelm;
                pathjoin_help($value, $elms, $res);
            }
        } else {
            die("Houston we have a problem");
        }
    }

    function pathjoin($a) {
        $res = array();
        pathjoin_help($a, array(), $res);
        return $res;
    }

    print_r(
        pathjoin(
            array (
              'a' =>
              array (
                'b1' =>
                array (
                  'c1' => '1',
                  'c2' => 2,
                  'c3' => 3,
                ),
                'b2' =>
                array (
                  'c' => 4,
                ),
              ),
            )
        )
    );

    Houston we have a problem

    You changed:

    'c1' => 1

    to:

    'c1' => '1'

    and my code required integer.

    If you want the final item to be anything then you can use:

    function pathjoin_help($o, $elms, &$res) {
    if(is_array($o)) {
    $elms[] = null;
    foreach($o as $pathelm => $value) {
    $elms[count($elms)-1] = $pathelm;
    pathjoin_help($value, $elms, $res);
    }
    } else {
    $res[implode('/', $elms)] = $o;
    }
    }

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From alex@21:1/5 to All on Sun Jul 25 12:50:02 2021
    Il 25/07/21 02:36, Arne Vajhøj ha scritto:

    If you want the final item to be anything then you can use:

    Thanks :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From He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