Skip to content

Convert into php array from javascript object

Notifications You must be signed in to change notification settings

Osushi/jsobj2php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsobj2php

Packagist

Functions

  • Convert into php array from javascript object

Requirements

  • PHP >= 7.0.*

Usage

composer require osushi/jsobj2php

Examples

See: https://github.com/Osushi/jsobj2php/blob/master/example.php

<?php
require_once 'vendor/autoload.php';

use JsObj2Php\Converter;

$str = '{
baseprice:3300,
items:[{id:1,price:1000,commnet:"foo",memo:[]},{id:2,price:2000,memo:[]}],
counts:[10, 20],
message:"ほげ",
pickup:{id:1,price:1000,commnet:"foo",memo:[0, 1, 2]}
}';

var_export(Converter::execute($str, true)); // If here sets `Converter::execute($str)`, you can get stdClass object.
/*
array (
  'baseprice' => 3300,
  'items' =>
  array (
    0 =>
    array (
      'id' => 1,
      'price' => 1000,
      'commnet' => 'foo',
      'memo' =>
      array (
      ),
    ),
    1 =>
    array (
      'id' => 2,
      'price' => 2000,
      'memo' =>
      array (
      ),
    ),
  ),
  'counts' =>
  array (
    0 => 10,
    1 => 20,
  ),
  'message' => 'ほげ',
  'pickup' =>
  array (
    'id' => 1,
    'price' => 1000,
    'commnet' => 'foo',
    'memo' =>
    array (
      0 => 0,
      1 => 1,
      2 => 2,
    ),
  ),
)
*/

About

Convert into php array from javascript object

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages