<?php
$data = json_decode('{"keyword":[{"consultion":[{"title":"\u0645\u062f\u0629 \u0627\u0644\u0645\u0631\u0636","content":"\u0645\u0627 \u0645\u0639\u062f\u0644 \u0627\u0644\u0628\u0642\u0627\u0621 \u0639\u0644\u0649 \u0642\u064a\u062f \u0627\u0644\u062d\u064a\u0627\u0629 \u0628\u0639\u062f \u0627\u0644\u0625\u0635\u0627\u0628\u0629 \u0628\u0645\u0631\u0636 \u0627\u0644\u0623\u0644\u0632\u0647\u0627\u064a\u0645\u0631\u061f","id":"1"}]},{"consultion":[{"title":" \u0645\u062a\u0644\u0627\u0632\u0645\u0629 \u063a\u0631\u0648\u0628 \u0627\u0644\u0634\u0645\u0633","content":" \u0645\u0627 \"\u0645\u062a\u0644\u0627\u0632\u0645\u0629 \u063a\u0631\u0648\u0628 \u0627\u0644\u0634\u0645\u0633\" \u0627\u0644\u062a\u064a \u0642\u062f \u064a\u0639\u0627\u0646\u064a \u0645\u0646\u0647\u0627 \u0645\u0631\u064a\u0636 \u0627\u0644\u0623\u0644\u0632\u0647\u0627\u064a\u0645\u0631\u061f","id":"2"}]},{"consultion":[{"title":"\u0645\u062f\u0629 \u0627\u0644\u0645\u0631\u0636","content":"\u0645\u0627 \u0645\u0639\u062f\u0644 \u0627\u0644\u0628\u0642\u0627\u0621 \u0639\u0644\u0649 \u0642\u064a\u062f \u0627\u0644\u062d\u064a\u0627\u0629 \u0628\u0639\u062f \u0627\u0644\u0625\u0635\u0627\u0628\u0629 \u0628\u0645\u0631\u0636 \u0627\u0644\u0623\u0644\u0632\u0647\u0627\u064a\u0645\u0631\u061f","id":"1"}]}]}');
$data = $data->keyword[0];
$new_data['title'] = $data->title;
$new_data['consultion'] = $data->consultion;
echo json_encode($new_data);
?>
PS:
<?php
$data = json_decode('{"keyword":[{"consultion":[{"title":"\u0645\u062f\u0629 \u0627\u0644\u0645\u0631\u0636","content":"\u0645\u0627 \u0645\u0639\u062f\u0644 \u0627\u0644\u0628\u0642\u0627\u0621 \u0639\u0644\u0649 \u0642\u064a\u062f \u0627\u0644\u062d\u064a\u0627\u0629 \u0628\u0639\u062f \u0627\u0644\u0625\u0635\u0627\u0628\u0629 \u0628\u0645\u0631\u0636 \u0627\u0644\u0623\u0644\u0632\u0647\u0627\u064a\u0645\u0631\u061f","id":"1"}]},{"consultion":[{"title":" \u0645\u062a\u0644\u0627\u0632\u0645\u0629 \u063a\u0631\u0648\u0628 \u0627\u0644\u0634\u0645\u0633","content":" \u0645\u0627 \"\u0645\u062a\u0644\u0627\u0632\u0645\u0629 \u063a\u0631\u0648\u0628 \u0627\u0644\u0634\u0645\u0633\" \u0627\u0644\u062a\u064a \u0642\u062f \u064a\u0639\u0627\u0646\u064a \u0645\u0646\u0647\u0627 \u0645\u0631\u064a\u0636 \u0627\u0644\u0623\u0644\u0632\u0647\u0627\u064a\u0645\u0631\u061f","id":"2"}]},{"consultion":[{"title":"\u0645\u062f\u0629 \u0627\u0644\u0645\u0631\u0636","content":"\u0645\u0627 \u0645\u0639\u062f\u0644 \u0627\u0644\u0628\u0642\u0627\u0621 \u0639\u0644\u0649 \u0642\u064a\u062f \u0627\u0644\u062d\u064a\u0627\u0629 \u0628\u0639\u062f \u0627\u0644\u0625\u0635\u0627\u0628\u0629 \u0628\u0645\u0631\u0636 \u0627\u0644\u0623\u0644\u0632\u0647\u0627\u064a\u0645\u0631\u061f","id":"1"}]}]}');
$keywords = $data->keyword;
$new_data = array();
foreach ($keywords as $consultion) {
if (array_search($consultion, $new_data) === FALSE) {
$new_data[] = $consultion;
}
}
print_r($new_data);
//echo json_encode($new_data);
/******************** Example **********************************/
echo "\r\n\r\n";
$data = array();
$data['consultion'][] = array('title' => 'a', 'id' => 1);
$data['consultion'][] = array('title' => 'b', 'id' => 2);
$data['consultion'][] = array('title' => 'a', 'id' => 1); //duplicated
$encoded = json_encode($data);
$data = json_decode($encoded);
$new_data = array();
foreach ($data->consultion as $obj) {
if (array_search($obj, $new_data) === FALSE) {
$new_data[] = $obj;
}
}
print_r($new_data);
//echo json_encode($new_data);
?>
thank u, your are great :) –
Добро пожаловать :) – mhall