I don't know why but json_encode output has only an array in my second example.
Here is my codes:
$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;
}
and output is like this:
Example 1 output:
{"inline_keyboard":[[{"text":"Google","url":"http:\/\/google.com"}],[{"text":"test","callback_data":"test"}]]}
Example 2 output:
{"inline_keyboard":[[{"text":"Google","url":"http:\/\/google.com"}]]}
they should be same. what is happening?
With example1 you pass one array: ["inline_keyboard" => [[["text" => "Google", "url" => "http://google.com"]],[["text" => "test", "callback_data" => "test"]]]]
With example2, your are actually passing two arguments to the function inkeyboard
. One of them being [["text" => "Google", "url" => "http://google.com"]]
, the second one [["text" => "test", "callback_data" => "test"]]
.
It would work correctly, if you change example2 to:
$example2 = inkeyboard(array(array("text" => "Google", "url" => "http://google.com"),array(array("text" => "test", "callback_data" => "test"))));