Re: Replace punctuation in an associative array

The Doctor <[email protected]> Sat, 4 Mar 2023 05:19:54 -0000 (UTC)
Newsgroups comp.lang.php
Organization NetKnow News
Message-ID <[email protected]>
Arno Welzel <[email protected]> wrote:
: The Doctor, 2023-03-02 13:44:

: > I wish to replace [[ with [
: > 
: > AND
: > 
: > ]] with ] in an associative array .
: > 
: > How can I do this?

: What do you mean with "in an associative array"? The values? The keys?

: If you want to replace the characters in values:

: <?php
: $array = [
:   'value 1' => '[[something 1',
:   'value 2' => 'something 2]]',
: ];

: // Output array as it was before
: print_r($array);

: foreach($array as $key => $value)
: {
:   $array[$key] = str_replace(
:     [ '[[', ']]' ],
:     [ '[', ']' ],
:     $value
:   );
: }

: // Output as it was afterwards
: print_r($array);

What is happening is that the arrauy is being formed by a subarray
and the end product is seeing a [[ at the start and a ]]
at the end when it should be seeing a [ at the start and a ] at the end.



-- 
Member - Liberal International This is [email protected] Ici [email protected]
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com