R
R
rennamed_user1232021-09-23 11:37:49
PHP
rennamed_user123, 2021-09-23 11:37:49

How to properly convert an array?

I need to translate this array into php

{
    "program_id": "CC1234",
    "offerings": [{
        "offering_id": "RP445555",
        "location_id": "B2222"
    }],
    "member_id": "10000-01",
    "registration_type": "online",
    "dry_run": false
}


array(
        "member_id" => $_COOKIE['m_'],
        "program_id" => $program_id,
        "offerings" => array(
          "offering_id" => $offering_id,
          "location_id" => $location_id
        ),
        "registration_type" => "online"
      )

But I understand that I did not translate it correctly

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2021-09-23
@Rsa97

[
    "program_id" => "CC1234",
    "offerings": ,
    "member_id" => "10000-01",
    "registration_type" => "online",
    "dry_run" => false
]

S
Slava Rozhnev, 2021-09-23
@rozhnev

Use the json_decode function :

$json = '
{
    "program_id": "CC1234",
    "offerings": [{
        "offering_id": "RP445555",
        "location_id": "B2222"
    }],
    "member_id": "10000-01",
    "registration_type": "online",
    "dry_run": false
}';

$php_array = json_decode($json, true);

var_export($php_array);

Share PHP code
array (
  'program_id' => 'CC1234',
  'offerings' => 
  array (
    0 => 
    array (
      'offering_id' => 'RP445555',
      'location_id' => 'B2222',
    ),
  ),
  'member_id' => '10000-01',
  'registration_type' => 'online',
  'dry_run' => false,
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question