首页 > 解决方案 > codeigniter 出了点问题,是真的吗?

问题描述

在 windows、php5.5 和 ci 3.1.8 中进行测试我创建了一个 test.php,如下所示:

<?php
    session_start();
    $_SESSION['admin']="1";
    $str =array("_SESSION"=>array("isadmin"=>"admin","user"=>"user1"));
    extract($str);
    print_r($_SESSION);

运行它,返回结果:Array ( [isadmin] => admin [user] => user1 )

删除会话文件,并在 ci 中创建一个 Welcome.php,如下所示:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *         http://example.com/index.php/welcome
 *    - or -
 *         http://example.com/index.php/welcome/index
 *    - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see https://codeigniter.com/user_guide/general/urls.html
 */
public function index()
{
    $this->load->view('welcome_message');
}
public function test()
{
    session_start();
    $_SESSION['admin']="1";
    $str =array("_SESSION"=>array("isadmin"=>"admin","user"=>"user1"));
    extract($str);
    print_r($_SESSION);
}

}

并在http://localhost/index.php/welcome/test运行 返回结果:

数组( [管理员] => 1 )

操作的结果是不一样的。有事吗?

标签: phpcodeigniter

解决方案


extract :将数组中的变量导入到当前符号表中。

只是当前符号表

http://php.net/manual/en/function.extract.php


推荐阅读