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


PHP toArray函数代码示例

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


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

示例1: toArray

function toArray($xml)
{
    if (is_string($xml)) {
        $xml = new SimpleXMLElement($xml);
    }
    $children = $xml->children();
    if (!$children) {
        return (string) $xml;
    }
    $arr = array();
    foreach ($children as $key => $node) {
        $node = toArray($node);
        // support for 'anon' non-associative arrays
        if ($key == 'anon') {
            $key = count($arr);
        }
        // if the node is already set, put it into an array
        if (isset($arr[$key])) {
            if (!is_array($arr[$key]) || $arr[$key][0] == null) {
                $arr[$key] = array($arr[$key]);
            }
            $arr[$key][] = $node;
        } else {
            $arr[$key] = $node;
        }
    }
    return $arr;
}
开发者ID:alexsharma68,项目名称:helios-ats-importer,代码行数:28,代码来源:helios-ajax.php

示例2: SaveCategory

 /**
  * Saves a category to the database
  * Or updates an existing category
  *
  * @url POST /
  * @url PUT /$id
  */
 public function SaveCategory($id = null, $data)
 {
     // Only process valid data
     if ($this->ValidateCategory($data)) {
         // Format for update/insert query
         $dbData = array('name' => $data->Name);
         // Update existing user?
         if ($id) {
             $this->Db()->where('id', $id);
             if ($this->Db()->update('Categories', $dbData)) {
                 $category = new CategoryModel($id, $data->Name);
             } else {
                 throw new RestException(500, 'Update mislukt: ' . $this->Db()->getLastError());
             }
             // Add new user
         } else {
             $id = $this->Db()->insert('Categories', $dbData);
             if ($id) {
                 $category = new CategoryModel($id, $data->Name);
             } else {
                 throw new RestException(500, 'Toevoegen mislukt: ' . $this->Db()->getLastError());
             }
         }
         return $category > toArray();
     }
 }
开发者ID:nielswitte,项目名称:PitchHitRun,代码行数:33,代码来源:CategoriesController.php

示例3: parseWebVTT

function parseWebVTT($captionUrl = NULL, $descUrl = NULL)
{
    if ($captionUrl) {
        $captionFile = @file_get_contents($captionUrl);
        if ($captionFile) {
            $captionArray = toArray('captions', $captionFile);
        } else {
            echo '1';
            // unable to read caption file;
        }
        if ($descUrl) {
            $descFile = @file_get_contents($descUrl);
            if ($descFile) {
                $descArray = toArray('desc', $descFile);
            } else {
                // do nothing
                // description file is not required
            }
        }
        if (sizeof($captionArray) > 0) {
            writeOutput($captionArray, $descArray);
        } else {
            // do nothing
            // an error has occurred (and hopefully an error code was displayed)
        }
    } else {
        echo '0';
        // insuficcient parameters were passed by URL
    }
}
开发者ID:ideasatrandom,项目名称:ableplayer,代码行数:30,代码来源:ableplayer-transcript-maker.php

示例4: testFindAllUsersByDepartmentAndRoles

 public function testFindAllUsersByDepartmentAndRoles()
 {
     $this->users = $this->em->getRepository('AppBundle:User')->findAllUsersByDepartmentAndRoles(1, $this->em->getRepository('AppBundle:Role')->findOneByRole('ROLE_USER'));
     foreach ($this->users as $this->user) {
         $this->assertEquals(1, $this->user->getFieldOfStudy()->getDepartment()->getId());
         $this->assertContains(toArray('ROLE_USER'), $this->user->getRoles());
     }
 }
开发者ID:vegardbb,项目名称:webpage,代码行数:8,代码来源:UserRepositoryFunctionalTest.php

示例5: importUsers

function importUsers($users, $questions)
{
    $rows = array();
    foreach ($users as $user)
    {
        $username = arrayExtract($user, "username");
        if(!$username) continue;
        $username = str_replace(" ", "", $username);
        if(!$username) continue;

    //1 insert into user
        $userRow = array();
        $userRow["table"] = "user";
        $userRow["username"] = $username;
        $userRow["password"] = md5($username);
        $rows[] = $userRow;

    //2 insert into user_answer 1 row per user column
        foreach ($user as $column => $userValues)
        {
            if(!isset($questions[$column]) || !$userValues) continue;

            $q = $questions[$column];
//TODO: if question type == multiple,  $userValue is array: insert several rows
            $userValues = toArray($userValues, ";");
            foreach ($userValues as $key => $userValue)
            {
                $row = array();
                $row["table"] = "user_answer";
                $row["username"] = $username;
//              $row["field"] = $column;
//              $row["value"] = $userValue;
                $row["question_id"] = $q["id"];
                $answer = findAnswer($q, $userValue);
                if($answer)
                {
                    $row["answer_id"] = $answer["id"];
//                  $row["answer"] = $answer;

                    if(@$answer["value"])
                        $row["answer_value"] = $answer["value"];
                    else if(@$answer["data_type"] == "number")
                        $row["answer_value"] = $userValue;
                    else if(@$answer["data_type"] == "text")
                        $row["answer_text"] = $userValue;
                }
                else if(@$q["data_type"] == "number")
                    $row["answer_value"] = $userValue;
                else if(@$q["data_type"] == "text")
                    $row["answer_text"] = $userValue;

                if(@$row["answer_id"] || @$row["answer_text"] || @$row["answer_value"])
                    $rows[] = $row;
            }
        }
    }
    return $rows;
}
开发者ID:araynaud,项目名称:FoodPortrait,代码行数:58,代码来源:import_functions.php

示例6: submit

function submit($option)
{
    global $stack, $mainframe;
    // get values from gui of script
    $website = JRequest::getVar('http_host', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    if (substr($website, -1) != "/") {
        $website = $website . "/";
    }
    $page_root = JRequest::getVar('document_root', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $sitemap_file = $page_root . JRequest::getVar('sitemap_url', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $sitemap_url = $website . JRequest::getVar('sitemap_url', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $sitemap_form = JRequest::getVar('sitemap_url', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $priority = JRequest::getVar('priority', '1.0', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $forbidden_types = toArray(JRequest::getVar('forbidden_types', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML));
    $exclude_names = toArray(JRequest::getVar('exclude_names', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML));
    $freq = JRequest::getVar('freq', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $modifyrobots = JRequest::getVar('robots', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $method = JRequest::getVar('method', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $level = JRequest::getVar('levels', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $maxcon = JRequest::getVar('maxcon', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $timeout = JRequest::getVar('timeout', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $whitelist = JRequest::getVar('whitelist', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML);
    $priority >= 1 ? $priority = "1.0" : null;
    $xmlconfig = genConfig($priority, $forbidden_types, $exclude_names, $freq, $method, $level, $maxcon, $sitemap_form, $page_root, $timeout);
    if (substr($page_root, -1) != "/") {
        $page_root = $page_root . "/";
    }
    $robots = @JFile::read($page_root . 'robots.txt');
    preg_match_all("/Disallow:(.*?)\n/", $robots, $pos);
    if ($exclude_names[0] == "") {
        unset($exclude_names[0]);
    }
    foreach ($pos[1] as $disallow) {
        $disallow = trim($disallow);
        if (strpos($disallow, $website) === false) {
            $disallow = $website . $disallow;
        }
        $exclude_names[] = $disallow;
    }
    $forbidden_strings = array("print=1", "format=pdf", "option=com_mailto", "component/mailto", "/mailto/", "mailto:", "login", "register", "reset", "remind");
    foreach ($exclude_names as $name) {
        $name != "" ? $forbidden_strings[] = $name : null;
    }
    $stack = array();
    $s = microtime(true);
    if ($whitelist == "yes") {
        AntiFloodControl($website);
    }
    $file = genSitemap($priority, getlinks($website, $forbidden_types, $level, $forbidden_strings, $method, $maxcon, $timeout), $freq, $website);
    writeXML($file, $sitemap_file, $option, $sitemap_url);
    writeXML($xmlconfig, $page_root . "/administrator/components/com_jcrawler/config.xml", $option, $sitemap_url);
    $mainframe->enqueueMessage("total time: " . round(microtime(true) - $s, 4) . " seconds");
    if ($modifyrobots == 1) {
        modifyrobots($sitemap_url, $page_root);
    }
    HTML_jcrawler::showNotifyForm($option, $sitemap_url);
}
开发者ID:albertobraschi,项目名称:Hab,代码行数:57,代码来源:admin.jcrawler.php

示例7: check_fee

 public function check_fee()
 {
     $sms = new transport();
     $params = array("OperID" => $this->sms['user_name'], "OperPass" => $this->sms['password']);
     $url = "http://221.179.180.158:9000/QxtSms/surplus";
     $result = $sms->request($url, $params);
     $result = toArray($result['body'], "resRoot");
     $str = "企信通短信平台,剩余:" . $result['rcode'][0] . "条";
     return $str;
 }
开发者ID:xcdxcd,项目名称:zhongchou,代码行数:10,代码来源:QXT_sms.php

示例8: index

 public function index(array $params)
 {
     // the page of planets we are looking at
     $page = array_val($params, 'page', 1);
     // get a list of the planets (for this page)
     list($pagination, $planet_models) = get_paginated_models('planet', $page);
     $pagination['base_url'] = '/planet/';
     $planet_data = toArray($planet_models);
     $tpl_vars = array('pagination' => $pagination, 'planets' => $planet_data);
     v('page/planet/planet_list', $tpl_vars);
 }
开发者ID:Tapac,项目名称:hotscot,代码行数:11,代码来源:planet.php

示例9: toArray

 function toArray($xml)
 {
     $array = json_decode(json_encode($xml), TRUE);
     foreach (array_slice($array, 0) as $key => $value) {
         if (empty($value)) {
             $array[$key] = NULL;
         } elseif (is_array($value)) {
             $array[$key] = toArray($value);
         }
     }
     return $array;
 }
开发者ID:natanshalva,项目名称:php-project,代码行数:12,代码来源:readxml.php

示例10: objectToArray

function objectToArray($object)
{
    if (is_array($object)) {
        foreach ($object as $k => $v) {
            if (is_object($v)) {
                $object[$k] = toArray($v);
            }
        }
    } else {
        $object = toArray($object);
    }
    return $object;
}
开发者ID:Soul0806,项目名称:MyWeb,代码行数:13,代码来源:app_helper.php

示例11: inhabitant_dialog

 public function inhabitant_dialog(array $params)
 {
     $tpl_vars = array();
     $planets = get_models('planet');
     $tpl_vars['planets'] = toArray($planets);
     // are we editing an existing inhabitant
     if ($inhabitantID = array_val($params, 'inhabitantID')) {
         $inhabitant = m('inhabitant', $inhabitantID);
         $tpl_vars['inhabitantID'] = $inhabitant->getID();
         $tpl_vars['name'] = $inhabitant->get_name();
         $tpl_vars['inhabitant_planet'] = $inhabitant->get_planet()->toArray();
     }
     v('partial/inhabitant/inhabitant_form', $tpl_vars);
 }
开发者ID:Tapac,项目名称:hotscot,代码行数:14,代码来源:inhabitant.php

示例12: toArray

function toArray($obj)
{
    if (is_object($obj)) {
        $obj = (array) $obj;
    }
    if (is_array($obj)) {
        $new = array();
        foreach ($obj as $key => $val) {
            $new[$key] = toArray($val);
        }
    } else {
        $new = $obj;
    }
    return $new;
}
开发者ID:andrinda,项目名称:php-backend-generator,代码行数:15,代码来源:fungsi.php

示例13: insertQuestion

function insertQuestion($varname, $vardesc, $vartype, $club_id, $database, $whereString)
{
    //basic error checking
    include_once includePath() . "/apply_gen.php";
    $typeArray = toArray($vartype);
    if (!isset($typeArray['type'])) {
        return "type map does not contain required 'type' attribute";
    }
    if ($typeArray['type'] == "select" && $vardesc == '') {
        return "description (required for select) left blank";
    }
    //add spaces to type array
    $vartype = str_replace(";", "; ", $vartype);
    $vartype = str_replace("|", "| ", $vartype);
    if ($database != "supplements" && $database != "baseapp" && $database != "custom") {
        return "internal error: invalid database {$database}";
    }
    $varname = escape($varname);
    $vardesc = escape($vardesc);
    $vartype = escape($vartype);
    $club_id = escape($club_id);
    //increment from highest orderId
    $result = mysql_query("SELECT MAX(orderId) FROM {$database} WHERE {$whereString}");
    if ($row = mysql_fetch_array($result)) {
        if (is_null($row[0])) {
            $orderId = 1;
        } else {
            $orderId = escape($row[0] + 1);
        }
        if ($database != "supplements") {
            mysql_query("INSERT INTO {$database} (orderId, varname, vardesc, vartype, category) VALUES ('{$orderId}', '{$varname}', '{$vardesc}', '{$vartype}', '" . $_SESSION['category'] . "')");
        } else {
            mysql_query("INSERT INTO supplements (orderId, varname, vardesc, vartype, club_id) VALUES ('{$orderId}', '{$varname}', '{$vardesc}', '{$vartype}', '{$club_id}')");
        }
        return true;
    } else {
        return "internal error";
        //this shouldn't occur, since MAX would return null if no rows are found
    }
}
开发者ID:uakfdotb,项目名称:oneapp,代码行数:40,代码来源:apply_admin.php

示例14: latexAppendQuestion

function latexAppendQuestion($name, $desc, $type, $answer)
{
    $typeArray = getTypeArray($type);
    $question_string = "";
    if ($typeArray['type'] == "text") {
        if ($name != "") {
            $question_string .= '\\textbf{' . latexSpecialChars($name) . '}';
            //add main in bold
        }
        if ($desc != "") {
            if ($name != "") {
                $question_string .= '\\newline';
            }
            $question_string .= '\\emph{' . latexSpecialChars($desc) . '}';
            //add description in italics
        }
        $question_string .= '\\newline\\newline';
        return $question_string;
    } else {
        if ($typeArray['type'] == "latex") {
            $question_string .= $desc;
            return $question_string;
        } else {
            if ($typeArray['type'] == "code") {
                $question_string .= '\\text{' . get_html_to_latex(page_convert($desc)) . '}';
                return $question_string;
            } else {
                if ($typeArray['type'] == "repeat") {
                    $num = $typeArray['num'];
                    $subtype_array = explode("|", $typeArray['subtype']);
                    $desc_array = explode("|", $desc);
                    $name_array = explode("|", $name);
                    if ($answer != '') {
                        $answer_array = toArray($answer, "|", "=");
                    } else {
                        $answer_array = array_fill(0, count($name_array) * $num, '');
                    }
                    //find minimum length, which will be the number to repeat for
                    $min_length = min(count($subtype_array), count($desc_array), count($name_array));
                    for ($i = 0; $i < $min_length * $num; $i++) {
                        $index = $i % $min_length;
                        $n = intval($i / $min_length);
                        $thisName = getRepeatThisValue($name_array, $index, $n);
                        $thisDesc = getRepeatThisValue($desc_array, $index, $n);
                        $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n));
                        $question_string .= latexAppendQuestion($thisName, $thisDesc, $thisType, $answer_array[$i]);
                    }
                } else {
                    if ($name != "") {
                        $question_string .= '\\textbf{' . latexSpecialChars($name) . '}';
                        //add question in bold
                    }
                    //add description (in bold) for essays and short answer
                    if (($typeArray['type'] == "essay" || $typeArray['type'] == "short") && $desc != "") {
                        if ($name != "") {
                            $question_string .= '\\newline';
                        }
                        $question_string .= '\\emph{' . latexSpecialChars($desc) . '}';
                        //add description in italics
                    }
                    //add a separator depending on main type of the question
                    if ($typeArray['type'] == "essay") {
                        $question_string .= "\n\n";
                    }
                    if ($typeArray['type'] == "select" && $typeArray['method'] != "dropdown") {
                        //in this case, we add tick marks and check the correct ones
                        $choices = explode(";", $desc);
                        //get answer as array in case we're using multiple selection
                        $config = $GLOBALS['config'];
                        $answerArray = explode($config['form_array_delimiter'], $answer);
                        //this is used to indent the answer choices
                        $question_string .= "\n\\begin{quote}\n";
                        //output each choice with check box before it on a separate line in the quote
                        for ($i = 0; $i < count($choices); $i++) {
                            $choice = $choices[$i];
                            if ($i != 0) {
                                $question_string .= "\\\\\n ";
                            }
                            if (in_array($choice, $answerArray)) {
                                $question_string .= '\\xbox';
                            } else {
                                $question_string .= '\\tickbox';
                            }
                            $question_string .= " \\hspace{4pt} " . latexSpecialChars($choice);
                        }
                        $question_string .= "\\end{quote}";
                    } else {
                        //append the response
                        if ($typeArray['type'] == "essay") {
                            if ($answer != "") {
                                $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . '\\end{quote}';
                            } else {
                                $question_string .= '\\vspace{5ex}';
                            }
                        } else {
                            if ($answer != "") {
                                $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . ' \\end{quote}';
                            } else {
                                $question_string .= '\\vspace{1ex}';
                            }
//.........这里部分代码省略.........
开发者ID:uakfdotb,项目名称:oneapp,代码行数:101,代码来源:latex.php

示例15: do_send_goods

 public function do_send_goods($payment_notice_id, $delivery_notice_sn)
 {
     require_once APP_ROOT_PATH . "system/utils/XmlBase.php";
     $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where id = " . $payment_notice_id);
     $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $payment_notice['order_id']);
     $payment = $GLOBALS['db']->getRow("select id,config from " . DB_PREFIX . "payment where class_name='AlipayBank'");
     $payment['config'] = unserialize($payment['config']);
     $gateway = "https://www.alipay.com/cooperate/gateway.do";
     $parameter = array('service' => 'send_goods_confirm_by_platform', 'partner' => $payment['config']['alipay_partner'], '_input_charset' => 'utf-8', 'invoice_no' => $delivery_notice_sn, 'transport_type' => 'EXPRESS', 'logistics_name' => 'NONE', 'trade_no' => $payment_notice['outer_notice_sn']);
     ksort($parameter);
     reset($parameter);
     $sign = '';
     $param = '';
     foreach ($parameter as $key => $val) {
         $sign .= "{$key}={$val}&";
         $param .= "{$key}=" . urlencode($val) . "&";
     }
     $param = substr($param, 0, -1);
     $sign = substr($sign, 0, -1) . $payment['config']['alipay_key'];
     $sign_md5 = md5($sign);
     $gateway = $gateway . "?" . $param . "&sign=" . $sign_md5 . "&sign_type=MD5";
     $result = file_get_contents($gateway);
     $result = toArray($result, "alipay");
     if ($result['is_success'][0] == 'T') {
         return "支付宝发货成功";
     } else {
         if ($result['error'] == 'ILLEGAL_ARGUMENT') {
             return $result['error'] . ' 参数不正确';
         } elseif ($result['error'] == 'TRADE_NOT_EXIST') {
             return $result['error'] . ' 交易单号有误';
         } elseif ($result['error'] == 'GENERIC_FAILURE') {
             return $result['error'] . ' 执行命令错误';
         } else {
             return $result['error'];
         }
     }
 }
开发者ID:norain2050,项目名称:fanwei_xindai_3.2,代码行数:37,代码来源:AlipayBank_payment.php


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