<bdo id='qtWRx'></bdo><ul id='qtWRx'></ul>

    1. <tfoot id='qtWRx'></tfoot>
      <i id='qtWRx'><tr id='qtWRx'><dt id='qtWRx'><q id='qtWRx'><span id='qtWRx'><b id='qtWRx'><form id='qtWRx'><ins id='qtWRx'></ins><ul id='qtWRx'></ul><sub id='qtWRx'></sub></form><legend id='qtWRx'></legend><bdo id='qtWRx'><pre id='qtWRx'><center id='qtWRx'></center></pre></bdo></b><th id='qtWRx'></th></span></q></dt></tr></i><div id='qtWRx'><tfoot id='qtWRx'></tfoot><dl id='qtWRx'><fieldset id='qtWRx'></fieldset></dl></div>

      <small id='qtWRx'></small><noframes id='qtWRx'>

      <legend id='qtWRx'><style id='qtWRx'><dir id='qtWRx'><q id='qtWRx'></q></dir></style></legend>
    2. PHP - 作为对象的关联数组

      PHP - associative array as an object(PHP - 作为对象的关联数组)

          <tbody id='hh0r5'></tbody>

      1. <tfoot id='hh0r5'></tfoot>

        1. <small id='hh0r5'></small><noframes id='hh0r5'>

              <i id='hh0r5'><tr id='hh0r5'><dt id='hh0r5'><q id='hh0r5'><span id='hh0r5'><b id='hh0r5'><form id='hh0r5'><ins id='hh0r5'></ins><ul id='hh0r5'></ul><sub id='hh0r5'></sub></form><legend id='hh0r5'></legend><bdo id='hh0r5'><pre id='hh0r5'><center id='hh0r5'></center></pre></bdo></b><th id='hh0r5'></th></span></q></dt></tr></i><div id='hh0r5'><tfoot id='hh0r5'></tfoot><dl id='hh0r5'><fieldset id='hh0r5'></fieldset></dl></div>
                <bdo id='hh0r5'></bdo><ul id='hh0r5'></ul>
                <legend id='hh0r5'><style id='hh0r5'><dir id='hh0r5'><q id='hh0r5'></q></dir></style></legend>
                本文介绍了PHP - 作为对象的关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                可能重复:
                将数组转换为PHP对象

                我正在创建一个简单的 PHP 应用程序,我想使用 YAML 文件作为数据存储.我将数据作为关联数组获取,例如以下结构:

                I'm creating a simple PHP application and I would like to use YAML files as a data storage. I will get the data as an associative array, with this structure for example:

                $user = array('username' => 'martin', 'md5password' => '5d41402abc4b2a76b9719d911017c592')
                

                但是,我想用一些函数来扩展关联数组并使用 -> 运算符,所以我可以这样写:

                However, I would like to extend the associative array with some functions and use the -> operator, so I can write something like this:

                $user->username = 'martin';  // sets $user['username']
                $user->setPassword('hello'); // writes md5 of 'hello' to $user['md5password']
                $user->save();               // saves the data back to the file
                

                在没有类定义的情况下,有没有一种好方法可以做到这一点?

                Is there a good way to do this without a class definition?

                基本上,我想在 PHP 中使用 JavaScript 样式的对象 :)

                Basically, I would like to have JavaScript style objects in PHP :)

                推荐答案

                投吧:

                $user = (object)$user;
                

                当然,还有其他更灵活的解决方案,例如创建一个实现 数组访问:

                Of course, there are other, more flexible solutions like creating a class that implements ArrayAccess:

                $user = new User(); // implements ArrayAccess
                
                echo $user['name'];
                // could be the same as...
                echo $user->name;
                

                这篇关于PHP - 作为对象的关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                <small id='xVzwg'></small><noframes id='xVzwg'>

                    <tbody id='xVzwg'></tbody>
                  <i id='xVzwg'><tr id='xVzwg'><dt id='xVzwg'><q id='xVzwg'><span id='xVzwg'><b id='xVzwg'><form id='xVzwg'><ins id='xVzwg'></ins><ul id='xVzwg'></ul><sub id='xVzwg'></sub></form><legend id='xVzwg'></legend><bdo id='xVzwg'><pre id='xVzwg'><center id='xVzwg'></center></pre></bdo></b><th id='xVzwg'></th></span></q></dt></tr></i><div id='xVzwg'><tfoot id='xVzwg'></tfoot><dl id='xVzwg'><fieldset id='xVzwg'></fieldset></dl></div>
                • <tfoot id='xVzwg'></tfoot>
                  <legend id='xVzwg'><style id='xVzwg'><dir id='xVzwg'><q id='xVzwg'></q></dir></style></legend>
                  • <bdo id='xVzwg'></bdo><ul id='xVzwg'></ul>