D
D
danilduck2015-04-23 22:45:13
PHP
danilduck, 2015-04-23 22:45:13

How to convert two dimensional JSON array to string?

There was a problem converting a two-dimensional array to a string (JSON).
An empty value is output without any error.

<?php
$arr = array(

array(
'type' => 0,
'text' => '1 блок'
),

array(
'type' => 0,
'text' => '2 блок'
),

array(
'type' => 0,
'text' => '3 блок'
)
);
echo json_encode($arr);
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alastor, 2015-04-23
@danilduck

copied your code and ran - writecodeonline.com/php
returned
[{"type":0,"text":"1 \u0431\u043b\u043e\u043a"},{"type":0,"text":"2 \u0431\u043b\u043e\u043a"},{"type":0,"text":"3 \u0431\u043b\u043e\u043a"}]

S
Sergey, 2015-04-23
@butteff

$arr = [
  [
    'type' => 0,
    'text' => '1 блок',
  ],
  
  [
    'type' => 0,
    'text' => '2 блок',
  ],
  
  [
    'type' => 0,
    'text' => '3 блок',
  ]
];

echo json_encode($arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question