数组编码JSON



我需要JSON的帮助。我怎么能做这样的东西在php使用JSON ENCODING ?基本上这就是我想要的输出。

{
"133": ["User1","assets/hey.jpg","a"],
"244": ["User2 Cobain","assets/aa.jpg","b"],
"3": ["User4","assets/abc.jpg","c"]
}

格式为{"userid":["fullname","img_path","add_info"]}

<?php 
include("../includes/connection.php");
$search= $mysqli->query("Select * from login_credentials");
        while($row = $search->fetch_assoc()) 
        {
            $userid = $row['UserID'];
            $fullname = $row['Fname'] . " " . $row['Lname'];
            //"133": []
        $c = array($fullname,'..//assets/elvis.jpg','http://html5-ninja.com');
            echo json_encode(array($user=>$c));             
        }
?>

不确定这是否是您正在寻找的,但是json_decode()创建了一个这样的数组:

array:3 [
  133 => array:3 [
    0 => "User1"
    1 => "assets/hey.jpg"
    2 => "a"
  ]
  244 => array:3 [
    0 => "User2 Cobain"
    1 => "assets/aa.jpg"
    2 => "b"
  ]
  3 => array:3 [
    0 => "User4"
    1 => "assets/abc.jpg"
    2 => "c"
  ]
]
代码:

  $json = '{
       "133": ["User1","assets/hey.jpg","a"],
       "244": ["User2 Cobain","assets/aa.jpg","b"],
       "3": ["User4","assets/abc.jpg","c"]
  }';
  var_dump(json_decode($json, true));

相关内容

  • 没有找到相关文章

最新更新