0
我不知道爲什麼,但在我的第二個例子中,json_encode輸出只有一個數組。如果我在函數中使用json_encode,它將刪除一個數組
這是我的代碼:
$example1 = json_encode(array("inline_keyboard" => array(array(array("text" => "Google", "url" => "http://google.com")),array(array("text" => "test", "callback_data" => "test")))));
$example2 = inkeyboard(array(array("text" => "Google", "url" => "http://google.com")),array(array("text" => "test", "callback_data" => "test")));
function inkeyboard($array){
$keyboard = array($array);
$resp = array("inline_keyboard" => $keyboard);
$reply = json_encode($resp);
return $reply;
}
和輸出是這樣的:
實施例1個輸出:
{"inline_keyboard":[[{"text":"Google","url":"http:\/\/google.com"}],[{"text":"test","callback_data":"test"}]]}
實施例2的輸出:
{"inline_keyboard":[[{"text":"Google","url":"http:\/\/google.com"}]]}
它們應該是相同的。發生什麼事?
OMG,我忘了在該函數的第二個參數的情況。數組讓我頭腦混亂。非常感謝。 –