Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #19363
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Replace punctuation in an associative array |
| Date | 2023-03-04 11:07 +0100 |
| Message-ID | <k6gjj7FdcegU1@mid.individual.net> (permalink) |
| References | <ttq5np$i9r$50@gallifrey.nk.ca> <k6dl2dFtv97U1@mid.individual.net> <ttukdq$1t41$1@gallifrey.nk.ca> |
On 3/4/23 06:19, The Doctor wrote:
> Arno Welzel <usenet@arnowelzel.de> 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.
>
>
>
You place your object in too many arrays, it had been better doing it
the "right way" from the beginning,
It's not that hard to create the json you want when using classes, in
like 20mins I managed to generate this json from my objects:
{
"store_id": null,
"api_token": null,
"checkout_id": null,
"txn_total": null,
"environment": null,
"action": null,
"token": [
{
"data_key": "1234",
"issuer_id": "645sddfvdrt4tefd"
},
{
"data_key": "5678",
"issuer_id": "645sddfvdrt4tefd"
}
],
"ask_cvv": null,
"order_no": null,
"cust_id": null,
"dynamic_descriptor": null,
"language": null,
"recur": {
"bill_now": null,
"recur_amount": null,
"start_date": null,
"recur_unit": null,
"recur_period": null,
"number_of_recurs": null
},
"cart": {
"items": [
{
"url": "https:\/\/example.net\/item?id=1",
"description": "item 1",
"product_code": "1",
"unit_cost": "100",
"quantity": "1"
},
{
"url": "https:\/\/example.net\/item?id=2",
"description": "item 2",
"product_code": "2",
"unit_cost": "200",
"quantity": "1"
}
],
"subtotal": null,
"tax": {
"amount": null,
"description": null,
"rate": null
}
},
"contact_details": {
"first_name": null,
"last_name": null,
"email": null,
"phone": null
},
"shipping_details": {
"address_1": null,
"address_2": null,
"city": null,
"province": null,
"country": null,
"postal_code": null
},
"billing_details": {
"address_1": null,
"address_2": null,
"city": null,
"province": null,
"country": null,
"postal_code": null
}
}
I assumed that all values has to always be there, like an empty token
list would be [] instead of null and so on, add two tokens and two items.
using __construct(...) you could make it possible to input the values at
once instead of how I done creating the object and then assign each
variable one by one. You have the opportunity to improve things.
https://pastebin.com/jnz1RYWj
sadly Moneris seems to want everything to be as strings, if you could
have used float/decimal/duble/int then you didn't have to convert
between string and a numeric value back and forth.
--
//Aho
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar
Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-02 12:44 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-02 14:23 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-03 01:03 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-03 10:36 +0100
Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <techfan55555@hotmail.com> - 2023-03-08 09:22 -0800
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:24 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-03 08:14 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 05:19 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 11:07 +0100
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-04 14:42 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 14:57 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 16:38 +0100
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 00:41 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 23:58 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 01:39 +0100
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-03-05 00:52 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 12:16 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-05 14:08 +0000
Re: Bureaucracy (Was: Replace punctuation in an associative array) "J.O. Aho" <user@example.net> - 2023-03-06 09:30 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 16:43 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-07 18:56 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 22:53 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-08 23:44 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:25 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-10 09:08 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-10 15:20 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-01 14:08 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-06 00:26 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-12 22:45 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 07:41 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 11:50 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 14:26 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 22:37 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 01:12 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-14 19:34 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 22:21 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-16 12:40 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-16 22:03 +0200
Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <yyyyyeeeee00000@writeme.com> - 2023-03-06 03:23 -0800
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-06 16:21 +0000
Re: Replace punctuation in an associative array V <vvvvvvvvvvvvvvvvvvvv11111@mail.ee> - 2023-04-03 06:55 -0700
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-03 14:18 +0000
Re: Replace punctuation in an associative array Angel <heyeeeeeeeeeeeeeeeeeee@gmail.com> - 2023-04-15 05:33 -0700
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-15 13:52 +0000
csiph-web