Php framework, data works in var_dump, but not in echo

I'm so confused right now, I'm using a code igniter frame block and passing an array to the view so that I can access the variable from the view.

So in this view, when I do

echo var_dump($data["mykey"]);

I get

string '43' (length=2)

but when i try

echo $data["mykey"];

I get

A PHP Error was encountered
Severity: Notice
Message: Undefined index: "mykey"
Line Number: 8

???

EDIT (the problem is that when a code igniter tries to return from a view to pass it back to the controller as a string, this is my conclusion, because if I put a stamp at the end of the view, it works)

An array $datais like this and in my opinion I'm trying to makeecho $data["myfield"][0]["data"]

array
  'myfield' => 
    array
      0 => 
        array
          'data' => string '1'
  'myfieldb' => 
    array
      0 => 
        array
          'data' => string '2'
+3
source share
2 answers

When I recreate what you specified in PHP

<?php

    $array = array(
              'myfield' => 
                array(
                  0 => 
                    array(
                      'data' => '1')),
              'myfieldb' => 
                array(
                  0 => 
                    array(
                      'data' => '2')));

    echo $array['myfield'][0]['data'];

?>

It sounds great.

, , , . print_r($data) , .

0

class controller extends CI_Controller {

function hello() {
  $data['world'] = 'world';
  $this->load->view('test');
 }
}

<html>
<head></head>
<body>
Hello <?php echo $world ?>;
</body>
</html>

, , .

, $data['mykey'] , , $mykey, $data['mykey'].

<html>
<head></head>
<body>
Your key is: <?php echo $mykey ?>;
</body>
</html>

user_guide

+3

All Articles