这是什么数据类型,参数

时间:2013-08-16 09:34:54

标签: php html mysql arrays parameters

如果我从db表( Mysql )读取数据,我会将其作为返回:

[{"name":"Mobile Groups","value":1,"target":null,"alias":"mb_group","required":1,"showNull":0},
{"name":"Beta Group","value":3,"target":null,"alias":"mb_group","required":1,"showNull":0},
{"name":"Delta Group","value":4,"target":null,"alias":"mb_group","required":1,"showNull":0}]

我无法在任何地方找到这种数据类型,但那不是数组,是吗?我可以将此数据转换为数组,我需要这些数据用于我的checboxes和单选按钮,因为我将使用 foreach 来控制它,这是可能的吗?

2 个答案:

答案 0 :(得分:1)

$string = '[{"name":"Mobile Groups","value":1,"target":null,"alias":"mb_group","required":1,"showNull":0},
{"name":"Beta Group","value":3,"target":null,"alias":"mb_group","required":1,"showNull":0},
{"name":"Delta Group","value":4,"target":null,"alias":"mb_group","required":1,"showNull":0}]';

$array = json_decode($string);

var_dump($array);

输出

array (size=3)
  0 => 
    object(stdClass)[1]
      public 'name' => string 'Mobile Groups' (length=13)
      public 'value' => int 1
      public 'target' => null
      public 'alias' => string 'mb_group' (length=8)
      public 'required' => int 1
      public 'showNull' => int 0
  1 => 
    object(stdClass)[2]
      public 'name' => string 'Beta Group' (length=10)
      public 'value' => int 3
      public 'target' => null
      public 'alias' => string 'mb_group' (length=8)
      public 'required' => int 1
      public 'showNull' => int 0
  2 => 
    object(stdClass)[3]
      public 'name' => string 'Delta Group' (length=11)
      public 'value' => int 4
      public 'target' => null
      public 'alias' => string 'mb_group' (length=8)
      public 'required' => int 1
      public 'showNull' => int 0

此外,您可以使用TRUE参数获取数组转换对象:

$array = json_decode($string, true);

答案 1 :(得分:0)

对我来说看起来像JSON,更具体地说是三个对象的JSON数组。

在PHP中,您应该能够json_decode()