2014-05-22 126 views
-8

只是想知道是否有可能以一個PHP數組轉換爲JSON字符串 繼承人的下面的PHP數組:轉換PHP數組JSON字符串

array ( 
    'players' => array ( 
      '123' => '345' 
      '567' => '789' 
    ), 
    'non_players' => array ( 
      0 => '71558060', 
      1 => '14451395', 
      2 => '16428783', 
      3 => '12070702', 
      4 => '16872249', 
      5 => '10081837', 
      6 => '10000363', 
      7 => '10084478', 
    ), 
) 

是否有可能轉換成JSON字符串?

+0

你檢查https://www.google.co.in/search?q=INSERT+IGNORE&ie=utf-8&oe=utf-8&client= ubuntu&channel = fs&gfe_rd = cr&ei = 6dF9U5eZN4We_waRvIHgCw#channel = fs&q = php + array + to + json –

+2

是的,它被稱爲[json_encode()](http://www.php.net/manual/en/function.json -encode.php) – Crackertastic

+1

在發佈到SO之前請不要想。 :) –

回答

0

你可以只使用json_encode(),從PHP手冊:http://www.php.net/manual/en/function.json-encode.php

+0

不只是把它變成一個JSON數組? – law

+0

PHP中的JSON只是一個字符串(特殊格式的字符串)。所以它會將PHP數組轉換爲有效的JSON字符串。 –