简体   繁体   English

将具有数组的JavaScript对象转换为PHP数组

[英]transform JavaScript object with arrays into a PHP array

Does anyone have a smart idea how to transform this javascript object into an associative php array? 有谁有一个聪明的主意如何将这个javascript对象转换为一个关联的php数组?

Note that I don't want to read this into PHP, I want the same data structure in PHP without going through each line and editing it eg adding '' and => . 请注意,我不想将其读入PHP,而是希望在PHP中使用相同的数据结构,而无需遍历每一行并对其进行编辑,例如添加''=>

module.exports = {
  base: '/',
  api: {
    sentry: 'https://7ed0a4e5846c4c31a44812bd5e37c2a1@sentry.io/257382',
    wp: {
      imgSize: {
        _380x270: 'medium',
      }
    }
  },
  y: 2017,
  href: {
    authors: '#',
    fb: '#',
    instagram: '#',
    de: 'https://wearede.com/',
  },
  faction: {
    subscribe: "/",
    search: "/",
  },
  search: {
    tags: [{
        t: 'Lifestyle',
        h: '#'
      },
      {
        t: 'Politics',
        h: '#'
      },
      {
        t: 'Economy',
        h: '#'
      },
    ],
    articles: [{
        t: 'იოლანდა ჰადიდმა ჯიჯი ჰადიდის და ზეინ მალიკის ერთობლივი ფოტო გამოაქვეყნა',
        h: '#',
      },
      {
        t: 'ლარი ევროსთან მიმართებით რეკორდულად გაუფასურდა',
        h: '#',
      },
    ]
  },
  menuMain: [{
      h: '#',
      t: 'სიახლეები'
    },
    {
      h: '#',
      t: 'ბიზნესი და ტექნოლოგია'
    },
    {
      h: '#',
      t: 'Lifestyle'
    },
    {
      h: '#',
      t: 'მოგზაურობა'
    },
    {
      h: '#',
      t: 'გასტრონომია'
    },
    {
      h: '#',
      t: '<i class="i i--hammock fz-20"></i>'
    },
  ],
  footer: {
    authors: [{
        i: 'https://picsum.photos/55/55',
        h: '#',
        n: 'Rusudan Tinatin',
        t: 'Author',
        d: 'ლარი ევროსთან მიმართებით რეკორდულად გაუფასურდა',
      },
      {
        i: 'https://picsum.photos/55/55',
        h: '#',
        n: 'Rusudan Tinatin',
        t: 'Author',
        d: 'იოლანდა ჰადიდმა ჯიჯი ჰადიდის და ზეინ მალიკის ერთობლივი ფოტო გამოაქვეყნა',
      },
      {
        i: 'https://picsum.photos/55/55',
        h: '#',
        n: 'Rusudan Tinatin',
        t: 'Author',
        d: 'ლარი ევროსთან მიმართებით რეკორდულად გაუფასურდა',
      },
    ],
    nav: [{
        t: 'პირობები',
        h: '#'
      },
      {
        t: 'პირადი ინფორმაცია',
        h: '#'
      },
      {
        t: 'ჩვენს შესახებ',
        h: '#'
      },
      {
        t: 'კონტაქტი',
        h: '#'
      },
      {
        t: 'ავტორები',
        h: '#'
      },
    ],
    cats: [{
        t: 'სიახლეები',
        h: '#'
      },
      {
        t: 'Lifestyle',
        h: '#'
      },
      {
        t: 'გასტრონომია',
        h: '#'
      },
      {
        t: 'ბიზნესი და ტექნოლოგია',
        h: '#'
      },
      {
        t: 'მოგზაურობა',
        h: '#'
      },
      {
        t: 'Hammock',
        h: '#'
      },
    ],
    articles: {
      items: articles.slice(0, 3),
      i: 'https://picsum.photos/380/260',
      t: 'დეკანოზი გიორგი მამალაძე სასამართლომ დამნაშავედ ცნო',
      h: '#',
    },
  }
}

At the moment I'm considering an option to record macros in vim, but that will take quite some time, and I see potential pitfalls in that approach. 目前,我正在考虑在vim中记录宏的选项,但这将花费相当长的时间,而且我认为这种方法存在潜在的缺陷。

Convert this object into a JSON string. 将此对象转换为JSON字符串。 Then in PHP, you can json_decode and var_export . 然后在PHP中,您可以json_decodevar_export

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM