当前位置: 首页>>代码示例>>PHP>>正文


PHP array2json函数代码示例

本文整理汇总了PHP中array2json函数的典型用法代码示例。如果您正苦于以下问题:PHP array2json函数的具体用法?PHP array2json怎么用?PHP array2json使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了array2json函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array2json

function array2json($arr)
{
    //if(function_exists('json_encode')) return json_encode($arr); //Lastest versions of PHP already has this functionality.
    $parts = array();
    $is_list = false;
    //Find out if the given array is a numerical array
    $keys = array_keys($arr);
    $max_length = count($arr) - 1;
    if ($keys[0] == 0 and $keys[$max_length] == $max_length) {
        //See if the first key is 0 and last key is length - 1
        $is_list = true;
        for ($i = 0; $i < count($keys); $i++) {
            //See if each key correspondes to its position
            if ($i != $keys[$i]) {
                //A key fails at position check.
                $is_list = false;
                //It is an associative array.
                break;
            }
        }
    }
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            //Custom handling for arrays
            if ($is_list) {
                $parts[] = array2json($value);
            } else {
                $parts[] = '"' . $key . '":' . array2json($value);
            }
            /* :RECURSION: */
        } else {
            $str = '';
            if (!$is_list) {
                $str = '"' . $key . '":';
            }
            //Custom handling for multiple data types
            if (is_numeric($value)) {
                $str .= $value;
            } elseif ($value === false) {
                $str .= 'false';
            } elseif ($value === true) {
                $str .= 'true';
            } else {
                $str .= '"' . addslashes($value) . '"';
            }
            //All other things
            $parts[] = $str;
        }
    }
    $json = implode(',', $parts);
    if ($is_list) {
        return '[' . $json . ']';
    }
    //Return numerical JSON
    return '{' . $json . '}';
    //Return associative JSON
}
开发者ID:neruruguay,项目名称:neru,代码行数:57,代码来源:Add_Item_query.php

示例2: reg

 public function reg()
 {
     $data = $_POST;
     foreach ($data as $key => $rec) {
         if (empty($rec)) {
             $data['error'] = $key;
             break;
         }
     }
     echo array2json($data);
     exit;
 }
开发者ID:babuzinga,项目名称:www.project.local,代码行数:12,代码来源:auth.php

示例3: array2json

 public static function array2json(array $arr)
 {
     $parts = array();
     $is_list = false;
     if (count($arr) > 0) {
         //Find out if the given array is a numerical array
         $keys = array_keys($arr);
         $max_length = count($arr) - 1;
         if ($keys[0] === 0 and $keys[$max_length] === $max_length) {
             //See if the first key is 0 and last key is length - 1
             $is_list = true;
             for ($i = 0; $i < count($keys); $i++) {
                 //See if each key correspondes to its position
                 if ($i !== $keys[$i]) {
                     //A key fails at position check.
                     $is_list = false;
                     //It is an associative array.
                     break;
                 }
             }
         }
         foreach ($arr as $key => $value) {
             $str = !$is_list ? '"' . $key . '":' : '';
             if (is_array($value)) {
                 //Custom handling for arrays
                 $parts[] = $str . array2json($value);
             } else {
                 //Custom handling for multiple data types
                 if (is_numeric($value) && !is_string($value)) {
                     $str .= $value;
                     //Numbers
                 } elseif (is_bool($value)) {
                     $str .= $value ? 'true' : 'false';
                 } elseif ($value === null) {
                     $str .= 'null';
                 } else {
                     $str .= '"' . addslashes($value) . '"';
                     //All other things
                 }
                 $parts[] = $str;
             }
         }
     }
     $json = implode(',', $parts);
     if ($is_list) {
         return '[' . $json . ']';
     }
     //Return numerical JSON
     return '{' . $json . '}';
     //Return associative JSON
 }
开发者ID:pollaeng,项目名称:gwt-php-service,代码行数:51,代码来源:GWT_RPC.php

示例4: drawHand

 function drawHand()
 {
     // draw HTML from class variables
     $card_html = array("H" => '&hearts;', "S" => '&spades;', "C" => '&clubs;', "D" => '&diams;');
     $ht_array = array();
     $ht_array['table_id'] = $this->table_id;
     $ht_array['dealer_position'] = $this->dealer_position;
     $ht_array['numberof_players'] = $this->numberof_players;
     $ht_array['last_error'] = $this->last_error;
     $ht_array['last_error_code'] = $this->last_error_code;
     $ht_array['last_message'] = $this->last_message;
     //			$ht_array['main_action'] = "<a class=\"actions\" onclick=\"playTurn()\"><b>Refresh</b></a>";
     $ht_array['main_action'] = $this->currentStateHtml();
     // following 3 lines was for initial testing to start game manually.
     //			$ht_array['main_action'] = "";
     //			if($this->current_state==0 || $this->current_state==H_STATE_SHOWDOWN || $this->current_state==H_STATE_CLOSED)
     //				$ht_array['main_action'] = "<a class=\"actions\" onclick=\"playTurn()\"><b>Refresh</b></a>";
     for ($i = 0; $i < 5; $i++) {
         if (isset($this->community_cards[$i])) {
             $card = $this->community_cards[$i];
             $url = '<img src="images/' . $card['value'] . $card['suit'] . '.jpg" border=0>';
         } else {
             $url = "";
         }
         $ht_array['community_cards'][] = $url;
     }
     $ht_array['pots'] = $this->pots;
     if (count($ht_array['pots']) == 0) {
         $ht_array['pots'] = array("");
     }
     // player data: $player_id $nick_name $table_stack $pocket_cards $current_share $current_state
     for ($i = 1; $i <= $this->numberof_players; $i++) {
         $pa = array();
         if (isset($this->hand_players[$i])) {
             $p = $this->hand_players[$i];
             $pa['player_id'] = $p->player_id;
             $pa['nick_name'] = $p->nick_name;
             $pa['table_stack'] = $p->table_stack;
             $pa['current_share'] = $p->current_share;
             $pa['action_url'] = "";
             $pa['pocket_cards'] = array("", "");
             $pa['current_state'] = $this->playerStateHtml($p->current_state);
             if ($this->current_state == H_STATE_SHOWDOWN) {
                 $pa['table_stack'] = $p->win_html;
             }
             if ($p->current_state == P_STATE_SITTING_OUT) {
                 $pa['table_stack'] = "Sitting Out";
             }
             $pa['action_url'] = $this->playerActionHtml($p);
             if (count($p->pocket_cards) > 0 && $p->player_id == $this->request['request_player_id'] || $this->current_state == H_STATE_SHOWDOWN && $p->current_state == P_STATE_WAITING) {
                 unset($pa['pocket_cards']);
                 for ($j = 0; $j < count($p->pocket_cards); $j++) {
                     $card = $p->pocket_cards[$j];
                     $suit = $card['suit'];
                     $pa['pocket_cards'][] = '<img src="images/' . $card['value'] . $card['suit'] . '.jpg" border=0>';
                 }
                 $this->addAnimation("pocket_cards" . $p->table_position);
             } else {
                 $pa['pocket_cards'] = array('<img src="images/back.jpg" border=0>', '<img src="images/back.jpg" border=0>');
             }
         } else {
             $pa['player_id'] = 0;
             $pa['nick_name'] = "<a class=\"actions1\" onclick=\"playSitOn(" . P_ACTION_SIT . ",{$i})\"><b>Sit On</b></a>";
             $pa['table_stack'] = "";
             $pa['pocket_cards'] = array("", "");
             $pa['current_share'] = "";
             $pa['action_url'] = "";
             $pa['current_state'] = "Empty";
         }
         $ht_array['players'][] = $pa;
     }
     $ht_array['animation_queue'] = $this->animation_queue;
     echo array2json($ht_array);
 }
开发者ID:sharma3,项目名称:Texas-Hold-em-Video-Poker,代码行数:74,代码来源:poker_holdem.php

示例5: cpjson

function cpjson($obj)
{
    if (ob_get_contents()) {
        ob_end_clean();
    }
    if (function_exists("json_encode")) {
        echojson(array2json($obj));
    } else {
        include_once dirname(__FILE__) . "/../pacotes/cpaint/cpaint2.inc.php";
        $cp = new cpaint();
        $cp->set_data($obj);
        $cp->return_data();
        exit;
    }
}
开发者ID:edmarmoretti,项目名称:i3geo,代码行数:15,代码来源:funcoes_gerais.php

示例6: html_entity_decode

}
$_SESSION["_current_file"] = $file;
$_level_key_name = $_SESSION['_level_key_name'];
$data = html_entity_decode(base64_decode($_POST['data']), ENT_QUOTES, "UTF-8");
if (copy($path, $path_tmp) == false) {
    echo "2###";
    exit;
}
if (@file_put_contents($path, $data, LOCK_EX) === false) {
    $error = true;
    echo "3###";
} else {
    $result = test_conf();
    if ($result !== true) {
        $error = true;
        echo "4###" . $result;
    } else {
        $xml_obj = new xml($_level_key_name);
        $xml_obj->load_file($path);
        $array_xml = $xml_obj->xml2array();
        $tree_json = array2json($array_xml, $path);
        $_SESSION['_tree_json'] = $tree_json;
        $_SESSION['_tree'] = $array_xml;
        echo "5###" . base64_encode($tree_json);
    }
}
if ($error == true) {
    @unlink($path);
    @copy($path_tmp, $path);
}
@unlink($path_tmp);
开发者ID:jhbsz,项目名称:ossimTest,代码行数:31,代码来源:save.php

示例7: fetchVocabularyService


//.........这里部分代码省略.........
                // Devuelve notas de un tema
                // array(tema_id,string,note_id,note_type,note_lang,note_text)
                $response = $service->fetchTermNotes($arg);
                break;
            case 'fetchTopTerms':
                // Array de términos tope
                // array(tema_id,string)
                $response = $service->fetchTopTerms($arg);
                break;
            case 'fetchLast':
                // Array de últimos términos creados
                // array(tema_id,string)
                $response = $service->fetchLast();
                break;
            case 'fetchDirectTerms':
                // Array de términos vinculados directamente con el termino (TG,TR,UF)
                // array(tema_id,string,relation_type_id)
                $response = $service->fetchDirectTerms($arg);
                break;
            case 'fetchTerms':
                // Devuelve lista de términos para una lista separada por comas de tema_id
                // array(tema_id,string)
                $response = $service->fetchTermsByIds($arg);
                break;
            case 'fetchRelatedTerms':
                // Devuelve lista de términos relacionados para una lista separada por comas de tema_id
                // array(tema_id,string)
                $response = $service->fetchRelatedTermsByIds($arg);
                break;
            case 'fetchTargetTerms':
                // Devuelve lista de términos mapeados para un tema_id
                // array(tema_id,string)
                $response = $service->fetchTargetTermsById($arg);
                break;
            case 'fetchURI':
                // Devuelve lista de enlaces linkeados para un tema_id
                // list of foreign links to term
                // array(type link,link)
                $response = $service->fetchURI($arg);
                break;
                //~ case 'fetchSourceTermsURI':
                //~ // Devuelve lista de términos propios que están mapeados para una URI provista por un término externo
                //~ // list of source terms who are mapped by URI provided by target vocabulary.
                //~ // array(tema_id,string,code,lang,date_create,date_mod)
                //~ $response = $service-> fetchSourceTermsByURI(rawurldecode($arg));
                //~ break;
            //~ case 'fetchSourceTermsURI':
            //~ // Devuelve lista de términos propios que están mapeados para una URI provista por un término externo
            //~ // list of source terms who are mapped by URI provided by target vocabulary.
            //~ // array(tema_id,string,code,lang,date_create,date_mod)
            //~ $response = $service-> fetchSourceTermsByURI(rawurldecode($arg));
            //~ break;
            case 'fetchSourceTerms':
                // Devuelve lista de términos propios que están mapeados para un determinado término
                // list of source terms who are mapped for a given term  provided by ANY target vocabulary.
                // array(tema_id,string,code,lang,date_create,date_mod)
                $response = $service->fetchSourceTerms($arg);
                break;
            case 'letter':
                // Array de términos que comienzan con una letra
                // array(tema_id,string,no_term_string,relation_type_id)
                // sanitice $letter
                $arg = trim(urldecode($arg));
                // comment this line for russian chars
                //$arg=secure_data($arg,"alnum");
                $response = $service->fetchTermsByLetter($arg);
                break;
            case 'fetchVocabularyData':
                // Devuelve detalles del vocabularios
                //array(vocabulario_id,titulo,autor,idioma,cobertura,keywords,tipo,cuando,url_base)
                $response = $service->fetchVocabularyData("1");
                break;
            default:
                $response = $service->describeService();
                break;
        }
        global $CFG;
        $arrayResume['status'] = CFG_SIMPLE_WEB_SERVICE == '1' ? 'available' : 'disable';
        $arrayResume['param'] = array("task" => $task, "arg" => $arg);
        $arrayResume['web_service_version'] = $CFG["VersionWebService"];
        $arrayResume['version'] = $CFG["Version"];
        $arrayResume["cant_result"] = count($response["result"]);
        $response["resume"] = $arrayResume;
        $xml_resume = array2xml($arrayResume, $name = 'resume', $standalone = FALSE, $beginning = FALSE);
        $xml_response = array2xml($response, $name = 'terms', $standalone = TRUE, $beginning = FALSE, $nodeChildName = 'term');
        switch ($output) {
            case 'json':
                header('Content-type: application/json');
                return array2json($response, 'vocabularyservices');
                break;
            case 'skos':
                header('Content-Type: text/xml');
                return $_SESSION[$_SESSION["CFGURL"]]["_PUBLISH_SKOS"] == '1' ? array2skos($response, 'vocabularyservices') : array2xml($response, 'vocabularyservices');
                break;
            default:
                header('Content-Type: text/xml');
                return array2xml($response, 'vocabularyservices');
        }
    }
}
开发者ID:kodizant,项目名称:TemaTres-Vocabulary-Server,代码行数:101,代码来源:fun.api.php

示例8: utf8_decode

    $output = utf8_decode($output);
    if (@file_put_contents($path, $output, LOCK_EX) === false) {
        echo "2###" . _("Failure to update XML File") . " (3)";
        $error = true;
    } else {
        $res = getTree($file);
        if (!is_array($res)) {
            echo $res;
            $error = true;
        } else {
            $tree = $res;
            $tree_json = array2json($tree, $path);
            $_SESSION['_tree_json'] = $tree_json;
            $_SESSION['_tree'] = $tree;
            $result = test_conf();
            if ($result !== true) {
                $error = true;
                echo "3###" . $result;
            }
        }
    }
}
if ($error == true) {
    @unlink($path);
    @copy($path_tmp, $path);
    $_SESSION['_tree'] = $tree_cp;
    $_SESSION['_tree_json'] = array2json($tree_cp, $path);
} else {
    echo "1###" . _("XML file update successfully") . "###" . base64_encode($tree_json);
}
@unlink($path_tmp);
开发者ID:jhbsz,项目名称:ossimTest,代码行数:31,代码来源:modify.php

示例9: exit

if (!$memm->is_login()) {
    exit("NoLogin");
}
if (!$memm->MemConnect($type, $curcon)) {
    exit("ConnectFail");
}
$thekey = str_replace("_ _rd", "'", $data[0]['key']);
$thekey = str_replace("_ _rx", "\\", $thekey);
$keylist = explode(" ", $thekey);
$list = $memm->MemGet($keylist);
$relist = array();
$relist[0] = array();
$relist[1] = array();
foreach ($list[0] as $key => $value) {
    $newkey = urlencode($key);
    $relist[0][$newkey] = array();
    if (is_array($value)) {
        $relist[0][$newkey][0] = serialize($value);
    } elseif (gettype($value) == 'object') {
        $relist[0][$newkey][0] = serialize($value);
    } else {
        $relist[0][$newkey][0] = $value;
    }
    $relist[0][$newkey][1] = gettype($value);
}
foreach ($list[1] as $key => $value) {
    $newkey = urlencode($key);
    $relist[1][$newkey] = $value;
}
echo array2json($relist, $cs);
开发者ID:npk,项目名称:memadmin,代码行数:30,代码来源:MemGet.php

示例10: update

 public function update($field)
 {
     $field_value = $_POST['field_value'];
     $id = $_POST['id'];
     if ($this->isAdmin && $this->validateField($field, $field_value) && $this->validateField('id', $id)) {
         //эта часть запроса общая для всех
         $query = "UPDATE banlist SET {$field} = ?";
         $d1_return = NULL;
         $d2_return = NULL;
         $is_blocked = isset($_POST['is_blocked']) ? $_POST['is_blocked'] : NULL;
         /*  Если пользователь на данный момент разблокирован, 
          *   а мы хотим установить дату блокировки > даты разблокировки
          *   => нужно заблокировать пользователя, а дату разблокировки поставить NULL.
          *   
          *   Если же пользователь на данный момент заблокирован, а мы хотим поставить 
          *   дату разблокировки > даты блокировки
          *   => пользователя нужно разблокировать.
          */
         if (($field === 'block_date' || $field === 'unblock_date') && $this->validateField('block_date', $_POST['block_date']) && $this->validateField('unblock_date', $_POST['unblock_date'])) {
             $d1 = new DateTime($_POST['block_date']);
             $d2 = new DateTime($_POST['unblock_date']);
             if ($d1 > $d2) {
                 $query .= ", unblock_date = NULL, is_blocked = 1";
                 $is_blocked = 1;
             } else {
                 $query .= ", is_blocked = 0";
                 $is_blocked = 0;
             }
             $d1_return = $d1->format('d.m.Y H:i:s');
             $d2_return = $d2->format('d.m.Y H:i:s');
         }
         //Если пользователь разблокирован - устанавливаем дату разблокировки на текущую,
         // заблокирован - дату блокировки на текущую, дату разблокировки удаляем:
         if ($field === 'is_blocked') {
             $date = new DateTime();
             $insert_date = $date->format('Y-m-d H:i:s');
             $return_date = $date->format('d.m.Y H:i:s');
             $query = $_POST['field_value'] == 0 ? $query . ", unblock_date = '{$insert_date}'" : $query . ", block_date = '{$insert_date}', unblock_date = NULL";
         }
         $query .= " WHERE id = ?";
         if ($field === 'block_date' || $field === 'unblock_date') {
             $date = new DateTime($field_value);
             $field_value = $date->format('Y-m-d H:i:s');
         }
         $this->db->query($query, $field_value, $id);
         $this->log->write("Изменена запись id: {$id}, поле: {$field}, значение: {$field_value}");
         if ($field === 'is_blocked') {
             echo array2json(array('date' => $return_date));
         } else {
             echo array2json(array('field' => $field_value, 'block_date' => $d1_return, 'unblock_date' => $d2_return, 'is_blocked' => $is_blocked));
         }
     } else {
         echo array2json(array('error' => $this->error_msg));
     }
 }
开发者ID:barkalovys,项目名称:banlist,代码行数:55,代码来源:ctrlBanlist.php

示例11: array2json

function array2json($arr, $jse = 1)
{
    if ($jse == 1) {
        if (function_exists('json_encode')) {
            return json_encode($arr);
            //Lastest versions of PHP already has this functionality.
        }
    } else {
        $parts = array();
        $is_list = false;
        if (!is_array($arr)) {
            return;
        }
        if (count($arr) < 1) {
            return '{}';
        }
        //Выясняем, данный  массив это числовой массив?!
        $keys = array_keys($arr);
        $max_length = count($arr) - 1;
        if ($keys[0] == 0 and $keys[$max_length] == $max_length) {
            //See if the first key is 0 and last key is length - 1
            $is_list = true;
            for ($i = 0; $i < count($keys); $i++) {
                //See if each key correspondes to its position
                if ($i != $keys[$i]) {
                    //A key fails at position check.
                    $is_list = false;
                    //It is an associative array.
                    break;
                }
            }
        }
        foreach ($arr as $key => $value) {
            if (is_array($value)) {
                //Custom handling for arrays
                if ($is_list) {
                    $parts[] = array2json($value, $jse);
                } else {
                    $parts[] = '"' . $key . '":' . array2json($value, $jse);
                }
                /* :РЕКУРСИЯ: */
            } else {
                $str = '';
                if (!$is_list) {
                    $str = '"' . $key . '":';
                }
                //Custom handling for multiple data types
                if (is_numeric($value)) {
                    $str .= $value;
                    //Numbers
                } elseif ($value === false) {
                    $str .= 'false';
                    //The booleans
                } elseif ($value === true) {
                    $str .= 'true';
                } else {
                    $str .= '"' . addslashes($value) . '"';
                    //All other things
                    // Есть ли более типов данных мы должны быть в поиске? (объект?)
                }
                $parts[] = $str;
            }
        }
        $json = implode(',', $parts);
        if ($is_list) {
            return '[' . $json . ']';
            //Вернуть как числовой  JSON
        }
        return '{' . $json . '}';
        //Вернуть как ассоциативный JSON
    }
}
开发者ID:norayr,项目名称:paperbod,代码行数:72,代码来源:functions.php

示例12: intval

 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
include_once "includes/config.php";
include_once "includes/utils.php";
$regid = intval($_GET['id']);
// Fetch available computers in the region
// Now connect to the db
$dbTrackHandler = connectDb();
// and see if we need to check any computer?
$computersQuery = $dbTrackHandler->query('SELECT id, lastsignal, name, laststatus ' . 'FROM computers ' . 'WHERE region = ' . $regid . ' ' . 'ORDER BY id; ');
//while($computersQuery->valid()) {
//	$computers[] = $computersQuery->current();
//	$computersQuery->next();
//}
$computers = $computersQuery->fetchAll();
header('Content-type: text/plain');
echo array2json($computers);
开发者ID:htruong,项目名称:geniemon,代码行数:30,代码来源:regionstats.php

示例13: array2json

function array2json($arr)
{
    $parts = array();
    $is_list = false;
    if (!is_array($arr)) {
        return;
    }
    if (count($arr) < 1) {
        return '{}';
    }
    //Find out if the given array is a numerical array
    $keys = array_keys($arr);
    $max_length = count($arr);
    if ($keys[0] == 0 and isset($keys[$max_length]) and $keys[$max_length] == $max_length) {
        //See if the first key is 0 and last key is length - 1
        $is_list = true;
        for ($i = 0; $i < count($keys); $i++) {
            //See if each key correspondes to its position
            if ($i != $keys[$i]) {
                //A key fails at position check.
                $is_list = false;
                //It is an associative array.
                break;
            }
        }
    }
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            //Custom handling for arrays
            if ($is_list) {
                $parts[] = array2json($value);
            } else {
                $parts[] = '"' . $key . '":' . array2json($value);
            }
            /* :RECURSION: */
        } else {
            $str = '';
            if (!$is_list) {
                $str = '"' . $key . '":';
            }
            //Custom handling for multiple data types
            if (is_numeric($value)) {
                $str .= $value;
            } elseif ($value === false) {
                $str .= 'false';
            } elseif ($value === true) {
                $str .= 'true';
            } else {
                $str .= '"' . addslashes($value) . '"';
            }
            //All other things
            // :TODO: Is there any more datatype we should be in the lookout for? (Object?)
            $parts[] = $str;
        }
    }
    $json = implode(',', $parts);
    if ($is_list) {
        return '[' . $json . ']';
    }
    //Return numerical JSON
    return '{' . $json . '}';
    //Return associative JSON
}
开发者ID:barkalovys,项目名称:banlist,代码行数:63,代码来源:array2json.php

示例14: sendError

 private function sendError($message)
 {
     echo array2json(array('error' => array('text' => $message)));
     die;
 }
开发者ID:JosepRivaille,项目名称:StyleCombo,代码行数:5,代码来源:index.php

示例15: array2json

function array2json($arr)
{
    $keys = array_keys($arr);
    $isarr = true;
    $json = "";
    for ($i = 0; $i < count($keys); $i++) {
        if ($keys[$i] !== $i) {
            $isarr = false;
            break;
        }
    }
    $json = $space;
    $json .= $isarr ? "[" : "{";
    for ($i = 0; $i < count($keys); $i++) {
        if ($i != 0) {
            $json .= ",";
        }
        $item = $arr[$keys[$i]];
        $json .= $isarr ? "" : $keys[$i] . ':';
        if (is_array($item)) {
            $json .= array2json($item);
        } else {
            if (is_string($item)) {
                $json .= '"' . str_replace(array("\r", "\n"), "", $item) . '"';
            } else {
                $json .= $item;
            }
        }
    }
    $json .= $isarr ? "]" : "}";
    return $json;
}
开发者ID:yunsite,项目名称:t-info-together,代码行数:32,代码来源:chat.php


注:本文中的array2json函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。