我怎样才能在php中对这个json数据进行排序?

时间:2018-03-08 11:41:06

标签: php json

如何在php中对这个json数据进行排序?
我尝试只显示 menu__item_name ,以帮助它正常工作。 但我不知道如何对数据进行排序    我想按menu_item_sort排序这个JSON数组?

我该怎么办?
我使用以下代码显示 menu__item_name

$obj = json_decode($list->mi_des);
$Name =$obj->{'menu__item_name'};


$arr_name = array($Name);
$arr_name_imp = implode(" ",$arr_name);
$arr_name_exp = explode("|",$arr_name_imp);

foreach($arr_name_exp as $i =>$key) {
    echo $key;
}

数据

{
  "menu__item_name":"test1|test2|test3",
  "menu_item_price":"775.00|100|30",
  "menu_item_description":"Melon Ball |Big mac|cocke",
  "menu_item_sort":"1|3|2",
  "menu_item_status":"1|1|1",
  "menu_item_display":"1|1|0"
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

解码json字符串,爆炸每个数组元素并按照Microchip Language Tool Shell Version 1.33 (Build date: Oct 9 2017). Copyright (c) 2012-2016 Microchip Technology Inc. All rights reserved *** Executing: "C:\Program Files (x86)\Microchip\xc16\v1.33\bin\bin/elf-gcc.exe" "-v" Using built-in specs. COLLECT_GCC=C:\Program Files (x86)\Microchip\xc16\v1.33\bin\bin/elf-gcc.exe Target: pic30-elf Configured with: /home/xc16/release-builds/build_20171009/src/XC_GCC/gcc/configure --build=i386-linux --host=i386-mingw32 --target=pic30-elf --disable-lto --disable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --disable-hosted-libstdcxx --with-gnu-as --with-gnu-ld --enable-languages=c --disable-nls --disable-libgomp --without-headers --disable-libffi --disable-bootstrap --prefix=/bin --libexecdir=/bin --program-prefix=pic30- --with-libelf=/home/xc16/release-builds/build_20171009/bin/XC_GCC-elf-mingw32-xclm/host-libs/ --with-dwarf2 --with-gmp=/home/xc16/release-builds/build_20171009/bin/XC_GCC-elf-mingw32-xclm/host-libs --with-ppl=/home/xc16/release-builds/build_20171009/bin/XC_GCC-elf-mingw32-xclm/host-libs --with-cloog=/home/xc16/release-builds/build_20171009/bin/XC_GCC-elf-mingw32-xclm/host-libs --with-zlib=/home/xc16/release-builds/build_20171009/bin/XC_GCC-elf-mingw32-xclm/host-libs --with-bugurl=http://www.microchip.com/support --with-host-libstdcxx=-Wl,-Bstatic,-lstdc++,-Bdynamic,-lm Thread model: single gcc version 4.5.1 (XC16, Microchip v1.33) Build date: Oct 9 2017 (Microchip Technology) 进行循环。希望这会有所帮助。

"menu_item_sort"

Demo