Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Only a fool fights in a burning house. -- Kank the Klingon, "Day of the Dove", stardate unknown


devel / comp.lang.php / convert array keys to paths

SubjectAuthor
* convert array keys to pathsalex
`* Re: convert array keys to pathsArne Vajhøj
 `* Re: convert array keys to pathsalex
  `* Re: convert array keys to pathsArne Vajhøj
   `* Re: convert array keys to pathsalex
    `- Re: convert array keys to pathsHe Llo

1
convert array keys to paths

<sbc9ua$11kl$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=258&group=comp.lang.php#258

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!CIrwOL7QAm/pDysrt9VS0Q.user.gioia.aioe.org.POSTED!not-for-mail
From: 1j9448a02@lnx159sneakemail.com.invalid (alex)
Newsgroups: comp.lang.php
Subject: convert array keys to paths
Date: Mon, 28 Jun 2021 12:57:14 +0200
Organization: Aioe.org NNTP Server
Lines: 29
Message-ID: <sbc9ua$11kl$1@gioia.aioe.org>
NNTP-Posting-Host: CIrwOL7QAm/pDysrt9VS0Q.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it-IT
X-Mozilla-News-Host: news://news.aioe.org:119
 by: alex - Mon, 28 Jun 2021 10:57 UTC

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.

Re: convert array keys to paths

<sdfpho$1ll9$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=302&group=comp.lang.php#302

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!LeVffQP25j5GAigzc2gaQA.user.46.165.242.75.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.php
Subject: Re: convert array keys to paths
Date: Fri, 23 Jul 2021 21:14:29 -0400
Organization: Aioe.org NNTP Server
Message-ID: <sdfpho$1ll9$1@gioia.aioe.org>
References: <sbc9ua$11kl$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="54953"; posting-host="LeVffQP25j5GAigzc2gaQA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Arne Vajhøj - Sat, 24 Jul 2021 01:14 UTC

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

Re: convert array keys to paths

<sdge67$4vj$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=304&group=comp.lang.php#304

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!XeyDHBeMmIt7nb5KMmJyiQ.user.46.165.242.91.POSTED!not-for-mail
From: 1j9448a02@lnx159sneakemail.com.invalid (alex)
Newsgroups: comp.lang.php
Subject: Re: convert array keys to paths
Date: Sat, 24 Jul 2021 09:06:47 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sdge67$4vj$1@gioia.aioe.org>
References: <sbc9ua$11kl$1@gioia.aioe.org> <sdfpho$1ll9$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="5107"; posting-host="XeyDHBeMmIt7nb5KMmJyiQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it-IT
 by: alex - Sat, 24 Jul 2021 07:06 UTC

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

Re: convert array keys to paths

<sdibn6$1eia$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=314&group=comp.lang.php#314

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!LeVffQP25j5GAigzc2gaQA.user.46.165.242.75.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.php
Subject: Re: convert array keys to paths
Date: Sat, 24 Jul 2021 20:36:51 -0400
Organization: Aioe.org NNTP Server
Message-ID: <sdibn6$1eia$1@gioia.aioe.org>
References: <sbc9ua$11kl$1@gioia.aioe.org> <sdfpho$1ll9$1@gioia.aioe.org>
<sdge67$4vj$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="47690"; posting-host="LeVffQP25j5GAigzc2gaQA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Arne Vajhøj - Sun, 25 Jul 2021 00:36 UTC

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

Re: convert array keys to paths

<sdjfkr$16j1$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=317&group=comp.lang.php#317

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!XeyDHBeMmIt7nb5KMmJyiQ.user.46.165.242.91.POSTED!not-for-mail
From: 1j9448a02@lnx159sneakemail.com.invalid (alex)
Newsgroups: comp.lang.php
Subject: Re: convert array keys to paths
Date: Sun, 25 Jul 2021 12:50:02 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sdjfkr$16j1$1@gioia.aioe.org>
References: <sbc9ua$11kl$1@gioia.aioe.org> <sdfpho$1ll9$1@gioia.aioe.org>
<sdge67$4vj$1@gioia.aioe.org> <sdibn6$1eia$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="39521"; posting-host="XeyDHBeMmIt7nb5KMmJyiQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it-IT
 by: alex - Sun, 25 Jul 2021 10:50 UTC

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 :)

Re: convert array keys to paths

<6cd0516a-7078-4afb-8a2c-a809bddc99dan@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=327&group=comp.lang.php#327

  copy link   Newsgroups: comp.lang.php
X-Received: by 2002:ac8:540f:: with SMTP id b15mr4281346qtq.193.1628166320705; Thu, 05 Aug 2021 05:25:20 -0700 (PDT)
X-Received: by 2002:a25:23ca:: with SMTP id j193mr5635852ybj.153.1628166320495; Thu, 05 Aug 2021 05:25:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!216.166.98.84.MISMATCH!Xbb.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.php
Date: Thu, 5 Aug 2021 05:25:20 -0700 (PDT)
In-Reply-To: <sdjfkr$16j1$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.37.157; posting-account=s3OxiwkAAABE2kqiXXKi7ZVC4Hsq_zQz
NNTP-Posting-Host: 82.131.37.157
References: <sbc9ua$11kl$1@gioia.aioe.org> <sdfpho$1ll9$1@gioia.aioe.org> <sdge67$4vj$1@gioia.aioe.org> <sdibn6$1eia$1@gioia.aioe.org> <sdjfkr$16j1$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6cd0516a-7078-4afb-8a2c-a809bddc99dan@googlegroups.com>
Subject: Re: convert array keys to paths
From: ya12983@mail.com (He Llo)
Injection-Date: Thu, 05 Aug 2021 12:25:20 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
Lines: 58
 by: He Llo - Thu, 5 Aug 2021 12:25 UTC

💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥💥

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor